Don't allow 2 tilesets to have the same name.

This commit is contained in:
dfighter1985 2014-07-22 15:35:14 +02:00
parent 395fafd2fe
commit c369f49b8a
4 changed files with 27 additions and 9 deletions

View file

@ -226,15 +226,13 @@ void TileEditorMainWindow::onTileSetAdd()
QString text = QInputDialog::getText(this, tr("Add Tile Set"), tr("Enter Tile Set name:"), QLineEdit::Normal, "", &ok);
if (ok && !text.isEmpty())
{
//if (ui.tileSetListWidget->findItems(text, Qt::MatchExactly).count() > 0)
//{
// QMessageBox::information( this, tr("Error Adding Tile Set"), tr("This name already exists") );
//}
//else
//{
//QModelIndex index = m_ui->tileSetLV->selectionModel()->currentIndex();
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
if( model->hasTileSet( text ) )
{
QMessageBox::information( this, tr("Error Adding Tile Set"), tr("This name already exists") );
return;
}
//if(index.isValid())
//{

View file

@ -67,7 +67,7 @@ public:
QVariant data(int column, int role) const;
int columnCount() const;
const QString &getTileSetName();
const QString &getTileSetName(){ return m_tileSetName; }
private:
QString m_tileSetName;
};

View file

@ -219,6 +219,24 @@ uint32 TileModel::getTileTypeSize(TileModel::TNodeTileType type)
return 0;
}
bool TileModel::hasTileSet( const QString &name )
{
for( int i = 0; i < rowCount(); i++ )
{
QModelIndex idx = index( i, 0 );
if( !idx.isValid() )
{
continue;
}
TileSetNode *n = reinterpret_cast< TileSetNode* >( idx.internalPointer() );
if( n->getTileSetName() == name )
return true;
}
return false;
}
void TileModel::selectFilenameDisplay(bool selected)
{
m_fileDisplay = selected;

View file

@ -87,6 +87,8 @@ public:
static TTileZoomFactor CurrentZoomFactor;
bool hasTileSet( const QString &name );
public Q_SLOTS:
void selectFilenameDisplay(bool selected);
void selectIndexDisplay(bool selected);