From c369f49b8afaf2375cc1a0b6d8936ebfd91475f1 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 22 Jul 2014 15:35:14 +0200 Subject: [PATCH] Don't allow 2 tilesets to have the same name. --- .../tile_editor/tile_editor_main_window.cpp | 14 ++++++-------- .../studio/src/plugins/tile_editor/tile_item.h | 2 +- .../src/plugins/tile_editor/tile_model.cpp | 18 ++++++++++++++++++ .../src/plugins/tile_editor/tile_model.h | 2 ++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp index d1199ebc9..a4643f7a0 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp @@ -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(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()) //{ diff --git a/code/studio/src/plugins/tile_editor/tile_item.h b/code/studio/src/plugins/tile_editor/tile_item.h index f89b20ab7..75108c77e 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.h +++ b/code/studio/src/plugins/tile_editor/tile_item.h @@ -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; }; diff --git a/code/studio/src/plugins/tile_editor/tile_model.cpp b/code/studio/src/plugins/tile_editor/tile_model.cpp index c167dbd44..7c444606f 100644 --- a/code/studio/src/plugins/tile_editor/tile_model.cpp +++ b/code/studio/src/plugins/tile_editor/tile_model.cpp @@ -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; diff --git a/code/studio/src/plugins/tile_editor/tile_model.h b/code/studio/src/plugins/tile_editor/tile_model.h index bd7d808fb..68d8cfeef 100644 --- a/code/studio/src/plugins/tile_editor/tile_model.h +++ b/code/studio/src/plugins/tile_editor/tile_model.h @@ -87,6 +87,8 @@ public: static TTileZoomFactor CurrentZoomFactor; + bool hasTileSet( const QString &name ); + public Q_SLOTS: void selectFilenameDisplay(bool selected); void selectIndexDisplay(bool selected);