Implemented tileset removal.

This commit is contained in:
dfighter1985 2014-07-23 18:35:26 +02:00
parent 068a10ea6d
commit acf3f656b2
5 changed files with 32 additions and 1 deletions

View file

@ -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<TileModel*>(m_ui->tileSetLV->model());
bool ok = model->removeRow( idx.row() );
//m_ui->tileSetLV->reset();
}
void TileEditorMainWindow::onActionAddTile(int tabId)
{
QFileDialog::Options options;

View file

@ -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);

View file

@ -505,7 +505,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_7">
<widget class="QToolButton" name="tileSetDeleteTB">
<property name="text">
<string>...</string>
</property>

View file

@ -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.

View file

@ -80,6 +80,8 @@ public:
void appendRow(const QList<Node*> &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);