2013-08-09 06:57:18 +02:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_qeditgroupsdialog.h"
|
|
|
|
#include "ui_lc_qeditgroupsdialog.h"
|
|
|
|
#include "lc_application.h"
|
|
|
|
#include "project.h"
|
|
|
|
#include "piece.h"
|
|
|
|
#include "group.h"
|
2013-08-16 03:25:51 +02:00
|
|
|
#include "lc_basewindow.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
lcQEditGroupsDialog::lcQEditGroupsDialog(QWidget *parent, void *data) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::lcQEditGroupsDialog)
|
|
|
|
{
|
2013-12-13 23:27:57 +01:00
|
|
|
m_lastItemClicked = NULL;
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
ui->setupUi(this);
|
2013-12-13 23:27:57 +01:00
|
|
|
connect(ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem *,int)), this, SLOT(onItemClicked(QTreeWidgetItem *,int)));
|
|
|
|
connect(ui->treeWidget,SIGNAL(itemDoubleClicked(QTreeWidgetItem *,int)), this, SLOT(onItemDoubleClicked(QTreeWidgetItem *,int)));
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
QPushButton *newGroup = ui->buttonBox->addButton(tr("New Group"), QDialogButtonBox::ActionRole);
|
|
|
|
connect(newGroup, SIGNAL(clicked()), this, SLOT(on_newGroup_clicked()));
|
|
|
|
|
|
|
|
options = (lcEditGroupsDialogOptions*)data;
|
|
|
|
|
|
|
|
addChildren(ui->treeWidget->invisibleRootItem(), NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcQEditGroupsDialog::~lcQEditGroupsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQEditGroupsDialog::accept()
|
|
|
|
{
|
|
|
|
updateParents(ui->treeWidget->invisibleRootItem(), NULL);
|
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQEditGroupsDialog::on_newGroup_clicked()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *currentItem = ui->treeWidget->currentItem();
|
|
|
|
|
|
|
|
if (currentItem && currentItem->data(0, PieceRole).value<uintptr_t>())
|
|
|
|
currentItem = currentItem->parent();
|
|
|
|
|
|
|
|
if (!currentItem)
|
|
|
|
currentItem = ui->treeWidget->invisibleRootItem();
|
|
|
|
|
|
|
|
Group *parentGroup = (Group*)currentItem->data(0, GroupRole).value<uintptr_t>();
|
|
|
|
Group *newGroup = lcGetActiveProject()->AddGroup(NULL, parentGroup, 0, 0, 0);
|
|
|
|
options->GroupParents.Add(NULL);
|
|
|
|
|
|
|
|
QTreeWidgetItem *groupItem = new QTreeWidgetItem(currentItem, QStringList(newGroup->m_strName));
|
2013-12-13 23:27:57 +01:00
|
|
|
groupItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable);
|
2013-08-09 06:57:18 +02:00
|
|
|
groupItem->setData(0, GroupRole, qVariantFromValue<uintptr_t>((uintptr_t)newGroup));
|
|
|
|
}
|
|
|
|
|
2013-12-13 23:27:57 +01:00
|
|
|
void lcQEditGroupsDialog::onItemClicked(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
|
|
|
if (item->flags() & Qt::ItemIsEditable)
|
|
|
|
{
|
|
|
|
m_clickTimer.stop();
|
|
|
|
|
|
|
|
if (m_lastItemClicked != item)
|
|
|
|
{
|
|
|
|
m_lastItemClicked = item;
|
|
|
|
m_editableDoubleClicked = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_clickTimer.start(QApplication::doubleClickInterval() + 50, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQEditGroupsDialog::onItemDoubleClicked(QTreeWidgetItem *item, int column)
|
|
|
|
{
|
|
|
|
if (item->flags() & Qt::ItemIsEditable)
|
|
|
|
{
|
|
|
|
m_editableDoubleClicked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQEditGroupsDialog::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
m_clickTimer.stop();
|
|
|
|
if (!m_editableDoubleClicked)
|
|
|
|
{
|
|
|
|
ui->treeWidget->editItem(m_lastItemClicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_editableDoubleClicked = false;
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
void lcQEditGroupsDialog::updateParents(QTreeWidgetItem *parentItem, Group *parentGroup)
|
|
|
|
{
|
|
|
|
Project *project = lcGetActiveProject();
|
|
|
|
|
|
|
|
for (int childIndex = 0; childIndex < parentItem->childCount(); childIndex++)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *childItem = parentItem->child(childIndex);
|
|
|
|
|
|
|
|
Piece *itemPiece = (Piece*)childItem->data(0, PieceRole).value<uintptr_t>();
|
|
|
|
|
|
|
|
if (itemPiece)
|
|
|
|
{
|
2014-04-10 06:46:48 +02:00
|
|
|
int pieceIndex = project->mPieces.FindIndex(itemPiece);
|
|
|
|
if (pieceIndex != -1)
|
|
|
|
options->PieceParents[pieceIndex] = parentGroup;
|
2013-08-09 06:57:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Group *itemGroup = (Group*)childItem->data(0, GroupRole).value<uintptr_t>();
|
|
|
|
|
2013-12-13 23:27:57 +01:00
|
|
|
strncpy(itemGroup->m_strName, childItem->text(0).toLocal8Bit(), sizeof(itemGroup->m_strName));
|
|
|
|
itemGroup->m_strName[sizeof(itemGroup->m_strName) - 1] = 0;
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
int groupIndex = 0;
|
|
|
|
for (Group *group = project->m_pGroups; group; group = group->m_pNext, groupIndex++)
|
|
|
|
{
|
|
|
|
if (itemGroup == group)
|
|
|
|
{
|
2013-08-16 01:43:18 +02:00
|
|
|
options->GroupParents[groupIndex] = parentGroup;
|
2013-08-09 06:57:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateParents(childItem, itemGroup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcQEditGroupsDialog::addChildren(QTreeWidgetItem *parentItem, Group *parentGroup)
|
|
|
|
{
|
|
|
|
Project *project = lcGetActiveProject();
|
|
|
|
|
|
|
|
for (Group *group = project->m_pGroups; group; group = group->m_pNext)
|
|
|
|
{
|
|
|
|
if (group->m_pGroup != parentGroup)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QTreeWidgetItem *groupItem = new QTreeWidgetItem(parentItem, QStringList(group->m_strName));
|
2013-12-13 23:27:57 +01:00
|
|
|
groupItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable);
|
2013-08-09 06:57:18 +02:00
|
|
|
groupItem->setData(0, GroupRole, qVariantFromValue<uintptr_t>((uintptr_t)group));
|
|
|
|
|
|
|
|
addChildren(groupItem, group);
|
|
|
|
}
|
|
|
|
|
2014-04-10 06:46:48 +02:00
|
|
|
for (int pieceIndex = 0; pieceIndex < project->mPieces.GetSize(); pieceIndex++)
|
2013-08-09 06:57:18 +02:00
|
|
|
{
|
2014-04-10 06:46:48 +02:00
|
|
|
Piece *piece = project->mPieces[pieceIndex];
|
|
|
|
|
2013-08-09 06:57:18 +02:00
|
|
|
if (piece->GetGroup() != parentGroup)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QTreeWidgetItem *pieceItem = new QTreeWidgetItem(parentItem, QStringList(piece->GetName()));
|
|
|
|
pieceItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
|
|
|
pieceItem->setData(0, PieceRole, qVariantFromValue<uintptr_t>((uintptr_t)piece));
|
|
|
|
}
|
|
|
|
}
|