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 a4643f7a0..6656ba793 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 @@ -88,6 +88,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) m_ui->tileSetLV->setModel(m_model); //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->tileSetLV->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &))); @@ -261,6 +262,18 @@ void TileEditorMainWindow::onTileSetAdd() } } +void TileEditorMainWindow::onTileSetDelete() +{ + QModelIndex idx = m_ui->tileSetLV->currentIndex(); + if( !idx.isValid() ) + return; + + TileModel *model = static_cast(m_ui->tileSetLV->model()); + bool ok = model->removeRow( idx.row() ); + + //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 0effbe087..a4f2fe623 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 @@ -48,6 +48,7 @@ public Q_SLOTS: void onActionReplaceImage(bool triggered); void onActionDeleteImage(bool triggered); void onTileSetAdd(); + void onTileSetDelete(); 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 cfa6c4fa1..ef2061e38 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 @@ -505,7 +505,7 @@ - + ... diff --git a/code/studio/src/plugins/tile_editor/tile_model.cpp b/code/studio/src/plugins/tile_editor/tile_model.cpp index 7c444606f..a5527fb56 100644 --- a/code/studio/src/plugins/tile_editor/tile_model.cpp +++ b/code/studio/src/plugins/tile_editor/tile_model.cpp @@ -140,6 +140,21 @@ void TileModel::appendRow(Node *item) rootItem->appendRow(item); } +bool TileModel::removeRows( int row, int count, const QModelIndex &parent ) +{ + int c = rootItem->childCount(); + if( row + count > c ) + return false; + + beginRemoveRows( QModelIndex(), row, row + count - 1 ); + + bool ok = rootItem->removeChildren( row, count ); + + endRemoveRows(); + + return ok; +} + TileSetNode *TileModel::createTileSetNode(QString tileSetName) { // Create the new tile set. diff --git a/code/studio/src/plugins/tile_editor/tile_model.h b/code/studio/src/plugins/tile_editor/tile_model.h index 68d8cfeef..cdf85acc3 100644 --- a/code/studio/src/plugins/tile_editor/tile_model.h +++ b/code/studio/src/plugins/tile_editor/tile_model.h @@ -80,6 +80,8 @@ public: void appendRow(const QList &items); void appendRow(Node *item); + bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ); + TileSetNode *createTileSetNode(QString tileSetName); static const char *getTileTypeName(TNodeTileType type);