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 d6524e27ff
commit 147c5604e0
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); QString text = QInputDialog::getText(this, tr("Add Tile Set"), tr("Enter Tile Set name:"), QLineEdit::Normal, "", &ok);
if (ok && !text.isEmpty()) 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()); 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()) //if(index.isValid())
//{ //{

View file

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

View file

@ -219,6 +219,24 @@ uint32 TileModel::getTileTypeSize(TileModel::TNodeTileType type)
return 0; 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) void TileModel::selectFilenameDisplay(bool selected)
{ {
m_fileDisplay = selected; m_fileDisplay = selected;

View file

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