Implemented tile deletion.

This commit is contained in:
dfighter1985 2014-07-26 01:57:50 +02:00
parent 4d0002a6f4
commit fc4856f28c
4 changed files with 42 additions and 4 deletions

View file

@ -215,6 +215,7 @@ void TileEditorMainWindow::onActionAddTile(bool triggered)
void TileEditorMainWindow::onActionDeleteTile(bool triggered) void TileEditorMainWindow::onActionDeleteTile(bool triggered)
{ {
onActionDeleteTile(m_ui->tileViewTabWidget->currentIndex());
} }
void TileEditorMainWindow::onActionReplaceImage(bool triggered) void TileEditorMainWindow::onActionReplaceImage(bool triggered)
@ -585,6 +586,32 @@ void TileEditorMainWindow::onActionAddTile(int tabId)
lv->setCurrentIndex( lv->model()->index( 0, 0, rootIdx ) ); lv->setCurrentIndex( lv->model()->index( 0, 0, rootIdx ) );
} }
void TileEditorMainWindow::onActionDeleteTile( int tabId )
{
QListView *lv = NULL;
switch( tabId )
{
case TAB_128: lv = m_ui->listView128; break;
case TAB_256: lv = m_ui->listView256; break;
}
QModelIndex idx = lv->currentIndex();
if( !idx.isValid() )
{
QMessageBox::information( this,
tr( "Deleting a tile" ),
tr( "You need to select a tile to delete is!" ) );
return;
}
int row = idx.row();
QModelIndex parent = idx.parent();
lv->model()->removeRow( row, parent );
//lv->reset();
}
TileModel* TileEditorMainWindow::createTileModel() TileModel* TileEditorMainWindow::createTileModel()
{ {
QStringList headers; QStringList headers;

View file

@ -69,6 +69,7 @@ private Q_SLOTS:
private: private:
void onActionAddTile(int tabId); void onActionAddTile(int tabId);
void onActionDeleteTile(int tabId);
TileModel* createTileModel(); TileModel* createTileModel();
Ui::TileEditorMainWindow *m_ui; Ui::TileEditorMainWindow *m_ui;

View file

@ -43,7 +43,7 @@ public:
virtual QVariant data(int column, int role) const; virtual QVariant data(int column, int role) const;
bool insertChildren(int position, int count, int columns); bool insertChildren(int position, int count, int columns);
bool removeChildren(int position, int count); virtual bool removeChildren(int position, int count);
bool insertColumns(int position, int columns); bool insertColumns(int position, int columns);
int row() const; int row() const;

View file

@ -142,13 +142,23 @@ void TileModel::appendRow(Node *item)
bool TileModel::removeRows( int row, int count, const QModelIndex &parent ) bool TileModel::removeRows( int row, int count, const QModelIndex &parent )
{ {
int c = rootItem->childCount(); Node *parentNode = NULL;
if( !parent.isValid() )
parentNode = rootItem;
else
parentNode = getItem( parent );
if( parentNode == NULL )
return false;
int c = parentNode->childCount();
if( row + count > c ) if( row + count > c )
return false; return false;
beginRemoveRows( QModelIndex(), row, row + count - 1 ); beginRemoveRows( parent, row, row + count - 1 );
bool ok = rootItem->removeChildren( row, count ); bool ok = parentNode->removeChildren( row, count );
endRemoveRows(); endRemoveRows();