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