From 9d1fec6ce19bec727ff352928cbef17554562693 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 23 Jul 2014 21:53:09 +0200 Subject: [PATCH] Implemented tileset rename. --HG-- branch : gsoc2014-dfighter --- .../tile_editor/tile_editor_main_window.cpp | 35 +++++++++++++++++++ .../tile_editor/tile_editor_main_window.h | 1 + .../tile_editor/tile_editor_main_window.ui | 2 +- .../src/plugins/tile_editor/tile_item.h | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) 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 6656ba793..8ab499bf8 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 @@ -89,6 +89,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) //m_ui->tileSetLV->setRootIndex(m_model->index(0,0)); connect(m_ui->tileSetAddTB, SIGNAL(clicked()), this, SLOT(onTileSetAdd())); connect(m_ui->tileSetDeleteTB, SIGNAL(clicked()), this, SLOT(onTileSetDelete())); + connect(m_ui->tileSetEditTB, SIGNAL(clicked()), this, SLOT(onTileSetEdit())); connect(m_ui->tileSetLV->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &))); @@ -274,6 +275,40 @@ void TileEditorMainWindow::onTileSetDelete() //m_ui->tileSetLV->reset(); } +void TileEditorMainWindow::onTileSetEdit() +{ + QModelIndex idx = m_ui->tileSetLV->currentIndex(); + if( !idx.isValid() ) + return; + + TileSetNode *node = reinterpret_cast< TileSetNode* >( idx.internalPointer() ); + QString name = node->getTileSetName(); + + bool ok = false; + + QString newName = QInputDialog::getText( this, + tr( "Edit tileset" ), + tr( "Enter tileset name" ), + QLineEdit::Normal, + name, + &ok ); + + if( !ok ) + return; + + TileModel *model = static_cast(m_ui->tileSetLV->model()); + if( model->hasTileSet( newName ) ) + { + QMessageBox::information( this, + tr("Tileset already exists"), + tr("A tileset with that name already exists!") ); + return; + } + + node->setTileSetName( newName ); + m_ui->tileSetLV->reset(); +} + void TileEditorMainWindow::onActionAddTile(int tabId) { QFileDialog::Options options; diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h index a4f2fe623..8719f799a 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h @@ -49,6 +49,7 @@ public Q_SLOTS: void onActionDeleteImage(bool triggered); void onTileSetAdd(); void onTileSetDelete(); + void onTileSetEdit(); void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex); void onZoomFactor(int level); diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui b/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui index ef2061e38..a88c11d0e 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui @@ -516,7 +516,7 @@ - + ... diff --git a/code/studio/src/plugins/tile_editor/tile_item.h b/code/studio/src/plugins/tile_editor/tile_item.h index 75108c77e..69fc89d71 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.h +++ b/code/studio/src/plugins/tile_editor/tile_item.h @@ -68,6 +68,8 @@ public: int columnCount() const; const QString &getTileSetName(){ return m_tileSetName; } + void setTileSetName( const QString &name ){ m_tileSetName = name; } + private: QString m_tileSetName; };