mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-26 17:16:20 +00:00
Implemented tileset move up and move down.
--HG-- branch : gsoc2014-dfighter
This commit is contained in:
parent
9d1fec6ce1
commit
c7ca20c748
7 changed files with 63 additions and 21 deletions
|
@ -87,9 +87,13 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
|||
// Set up the tile set list view.
|
||||
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->tileSetEditTB, SIGNAL(clicked()), this, SLOT(onTileSetEdit()));
|
||||
connect(m_ui->tileSetUpTB, SIGNAL(clicked()), this, SLOT(onTileSetUp()));
|
||||
connect(m_ui->tileSetDownTB, SIGNAL(clicked()), this, SLOT(onTileSetDown()));
|
||||
|
||||
connect(m_ui->tileSetLV->selectionModel(),
|
||||
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
|
||||
this, SLOT(changeActiveTileSet(const QModelIndex &, const QModelIndex &)));
|
||||
|
@ -236,23 +240,6 @@ void TileEditorMainWindow::onTileSetAdd()
|
|||
return;
|
||||
}
|
||||
|
||||
//if(index.isValid())
|
||||
//{
|
||||
// if(!model->insertRow(index.row()+1, index.parent()))
|
||||
// return;
|
||||
|
||||
// //updateActions()
|
||||
|
||||
// for(int column=0; column<model->columnCount(index.parent()); column++)
|
||||
// {
|
||||
// QModelIndex child = model->index(index.row()+1, column, index.parent());
|
||||
// model->setData(child, QVariant(text), Qt::EditRole);
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
|
||||
|
||||
// Create and append the new tile set to the model.
|
||||
TileSetNode *tileSet = model->createTileSetNode(text);
|
||||
|
||||
|
@ -271,8 +258,6 @@ void TileEditorMainWindow::onTileSetDelete()
|
|||
|
||||
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||
bool ok = model->removeRow( idx.row() );
|
||||
|
||||
//m_ui->tileSetLV->reset();
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileSetEdit()
|
||||
|
@ -309,6 +294,45 @@ void TileEditorMainWindow::onTileSetEdit()
|
|||
m_ui->tileSetLV->reset();
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileSetUp()
|
||||
{
|
||||
QModelIndex idx = m_ui->tileSetLV->currentIndex();
|
||||
if( !idx.isValid() )
|
||||
return;
|
||||
|
||||
if( idx.row() == 0 )
|
||||
return;
|
||||
|
||||
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||
if( model->rowCount() < 2 )
|
||||
return;
|
||||
|
||||
int r = idx.row();
|
||||
model->swapRows( r, r - 1 );
|
||||
|
||||
m_ui->tileSetLV->reset();
|
||||
m_ui->tileSetLV->setCurrentIndex( model->index( r - 1, 0 ) );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileSetDown()
|
||||
{
|
||||
QModelIndex idx = m_ui->tileSetLV->currentIndex();
|
||||
if( !idx.isValid() )
|
||||
return;
|
||||
|
||||
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||
if( model->rowCount() < idx.row() )
|
||||
return;
|
||||
if( model->rowCount() < 2 )
|
||||
return;
|
||||
|
||||
int r = idx.row();
|
||||
model->swapRows( r, r + 1 );
|
||||
|
||||
m_ui->tileSetLV->reset();
|
||||
m_ui->tileSetLV->setCurrentIndex( model->index( r + 1, 0 ) );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onActionAddTile(int tabId)
|
||||
{
|
||||
QFileDialog::Options options;
|
||||
|
|
|
@ -50,6 +50,8 @@ public Q_SLOTS:
|
|||
void onTileSetAdd();
|
||||
void onTileSetDelete();
|
||||
void onTileSetEdit();
|
||||
void onTileSetUp();
|
||||
void onTileSetDown();
|
||||
void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex);
|
||||
void onZoomFactor(int level);
|
||||
|
||||
|
|
|
@ -442,7 +442,7 @@
|
|||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_5">
|
||||
<widget class="QToolButton" name="tileSetUpTB">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
|
@ -453,7 +453,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_4">
|
||||
<widget class="QToolButton" name="tileSetDownTB">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
|
|
|
@ -155,6 +155,13 @@ void Node::appendRow(Node *item)
|
|||
m_childItems.append(item);
|
||||
}
|
||||
|
||||
void Node::swapRows( int a, int b )
|
||||
{
|
||||
Node *temp = m_childItems[ a ];
|
||||
m_childItems[ a ] = m_childItems[ b ];
|
||||
m_childItems[ b ] = temp;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
TileSetNode::TileSetNode(QString tileSetName, Node *parent) : m_tileSetName(tileSetName)
|
||||
|
|
|
@ -53,6 +53,8 @@ public:
|
|||
void appendRow(const QList<Node*> &items);
|
||||
void appendRow(Node *item);
|
||||
|
||||
void swapRows( int a, int b );
|
||||
|
||||
protected:
|
||||
QList<Node*> m_childItems;
|
||||
QVector<QVariant> m_itemData;
|
||||
|
|
|
@ -155,6 +155,11 @@ bool TileModel::removeRows( int row, int count, const QModelIndex &parent )
|
|||
return ok;
|
||||
}
|
||||
|
||||
void TileModel::swapRows( int a, int b )
|
||||
{
|
||||
rootItem->swapRows( a, b );
|
||||
}
|
||||
|
||||
TileSetNode *TileModel::createTileSetNode(QString tileSetName)
|
||||
{
|
||||
// Create the new tile set.
|
||||
|
|
|
@ -82,6 +82,8 @@ public:
|
|||
|
||||
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
|
||||
|
||||
void swapRows( int a, int b );
|
||||
|
||||
TileSetNode *createTileSetNode(QString tileSetName);
|
||||
|
||||
static const char *getTileTypeName(TNodeTileType type);
|
||||
|
|
Loading…
Reference in a new issue