create buttons to add items to map trees
This commit is contained in:
parent
ad1b651f96
commit
963b09c866
4 changed files with 108 additions and 15 deletions
|
@ -389,6 +389,11 @@ private:
|
||||||
void refreshRecentProjectsMenu();
|
void refreshRecentProjectsMenu();
|
||||||
|
|
||||||
void updateMapList();
|
void updateMapList();
|
||||||
|
void mapListAddItem();
|
||||||
|
void mapListRemoveItem();
|
||||||
|
void mapListAddGroup();
|
||||||
|
void mapListAddLayout();
|
||||||
|
void mapListAddArea();
|
||||||
|
|
||||||
void displayMapProperties();
|
void displayMapProperties();
|
||||||
void checkToolButtons();
|
void checkToolButtons();
|
||||||
|
|
|
@ -75,6 +75,7 @@ public:
|
||||||
QStandardItem *createGroupItem(QString groupName, int groupIndex, QStandardItem *fromItem = nullptr);
|
QStandardItem *createGroupItem(QString groupName, int groupIndex, QStandardItem *fromItem = nullptr);
|
||||||
QStandardItem *createMapItem(QString mapName, QStandardItem *fromItem = nullptr);
|
QStandardItem *createMapItem(QString mapName, QStandardItem *fromItem = nullptr);
|
||||||
|
|
||||||
|
QStandardItem *insertGroupItem(QString groupName);
|
||||||
QStandardItem *insertMapItem(QString mapName, QString groupName);
|
QStandardItem *insertMapItem(QString mapName, QString groupName);
|
||||||
|
|
||||||
QStandardItem *getItem(const QModelIndex &index) const;
|
QStandardItem *getItem(const QModelIndex &index) const;
|
||||||
|
@ -83,6 +84,7 @@ public:
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class MapTree;
|
||||||
void updateProject();
|
void updateProject();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -210,6 +210,24 @@ void MainWindow::initCustomUI() {
|
||||||
WheelFilter *wheelFilter = new WheelFilter(this);
|
WheelFilter *wheelFilter = new WheelFilter(this);
|
||||||
ui->mainTabBar->installEventFilter(wheelFilter);
|
ui->mainTabBar->installEventFilter(wheelFilter);
|
||||||
this->ui->mapListContainer->tabBar()->installEventFilter(wheelFilter);
|
this->ui->mapListContainer->tabBar()->installEventFilter(wheelFilter);
|
||||||
|
|
||||||
|
// Create buttons for adding and removing items from the mapList
|
||||||
|
QFrame *frame = new QFrame(this->ui->mapListContainer);
|
||||||
|
frame->setFrameShape(QFrame::NoFrame);
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout(frame);
|
||||||
|
|
||||||
|
QPushButton *buttonAdd = new QPushButton(QIcon(":/icons/add.ico"), "");
|
||||||
|
connect(buttonAdd, &QPushButton::clicked, [this]() { this->mapListAddItem(); });
|
||||||
|
QPushButton *buttonRemove = new QPushButton(QIcon(":/icons/delete.ico"), "");
|
||||||
|
connect(buttonRemove, &QPushButton::clicked, [this]() { this->mapListRemoveItem(); });
|
||||||
|
|
||||||
|
layout->addWidget(buttonAdd);
|
||||||
|
layout->addWidget(buttonRemove);
|
||||||
|
|
||||||
|
layout->setSpacing(0);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
|
this->ui->mapListContainer->setCornerWidget(frame, Qt::TopRightCorner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initExtraSignals() {
|
void MainWindow::initExtraSignals() {
|
||||||
|
@ -1178,12 +1196,6 @@ bool MainWindow::populateMapList() {
|
||||||
this->layoutListProxyModel->setSourceModel(this->layoutTreeModel);
|
this->layoutListProxyModel->setSourceModel(this->layoutTreeModel);
|
||||||
ui->layoutList->setModel(layoutListProxyModel);
|
ui->layoutList->setModel(layoutListProxyModel);
|
||||||
|
|
||||||
/// !TODO
|
|
||||||
// ui->mapList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
||||||
// ui->mapList->setDragEnabled(true);
|
|
||||||
// ui->mapList->setAcceptDrops(true);
|
|
||||||
// ui->mapList->setDropIndicatorShown(true);
|
|
||||||
// ui->mapList->setDragDropMode(QAbstractItemView::InternalMove);
|
|
||||||
on_toolButton_EnableDisable_EditGroups_clicked();
|
on_toolButton_EnableDisable_EditGroups_clicked();
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -1270,6 +1282,58 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
|
||||||
(this->*addFunction)(menu.exec(QCursor::pos()));
|
(this->*addFunction)(menu.exec(QCursor::pos()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::mapListAddGroup() {
|
||||||
|
QDialog dialog(this, Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||||
|
dialog.setWindowModality(Qt::ApplicationModal);
|
||||||
|
QDialogButtonBox newItemButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
|
||||||
|
connect(&newItemButtonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
||||||
|
connect(&newItemButtonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
||||||
|
|
||||||
|
QLineEdit *newNameEdit = new QLineEdit(&dialog);
|
||||||
|
newNameEdit->setClearButtonEnabled(true);
|
||||||
|
|
||||||
|
static const QRegularExpression re_validChars("[_A-Za-z0-9]*$");
|
||||||
|
QRegularExpressionValidator *validator = new QRegularExpressionValidator(re_validChars);
|
||||||
|
newNameEdit->setValidator(validator);
|
||||||
|
|
||||||
|
QFormLayout form(&dialog);
|
||||||
|
|
||||||
|
form.addRow("New Group Name", newNameEdit);
|
||||||
|
form.addRow(&newItemButtonBox);
|
||||||
|
|
||||||
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
|
QString newFieldName = newNameEdit->text();
|
||||||
|
if (newFieldName.isEmpty()) return;
|
||||||
|
this->mapGroupModel->insertGroupItem(newFieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::mapListAddLayout() {
|
||||||
|
// this->layoutTreeModel->insertMapItem(newMapName, newMap->layout->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::mapListAddArea() {
|
||||||
|
// this->mapAreaModel->insertMapItem(newMapName, newMap->location, newMapGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::mapListAddItem() {
|
||||||
|
switch (this->ui->mapListContainer->currentIndex()) {
|
||||||
|
case 0:
|
||||||
|
this->mapListAddGroup();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
this->mapListAddLayout();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
this->mapListAddArea();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::mapListRemoveItem() {
|
||||||
|
// !TODO
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction) {
|
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction) {
|
||||||
if (!triggeredAction) return;
|
if (!triggeredAction) return;
|
||||||
|
|
||||||
|
|
|
@ -156,15 +156,26 @@ bool MapGroupModel::dropMimeData(const QMimeData *data, Qt::DropAction action, i
|
||||||
rowCount++;
|
rowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->insertRows(firstRow, rowCount, parentIndex);
|
QStandardItem *groupItem = this->itemFromIndex(parentIndex);
|
||||||
|
if (groupItem->hasChildren()) {
|
||||||
int newItemIndex = 0;
|
this->insertRows(firstRow, rowCount, parentIndex);
|
||||||
for (QString mapName : droppedMaps) {
|
for (QString mapName : droppedMaps) {
|
||||||
QModelIndex mapIndex = index(firstRow, 0, parentIndex);
|
QModelIndex mapIndex = index(firstRow, 0, parentIndex);
|
||||||
QStandardItem *mapItem = this->itemFromIndex(mapIndex);
|
QStandardItem *mapItem = this->itemFromIndex(mapIndex);
|
||||||
createMapItem(mapName, mapItem);
|
createMapItem(mapName, mapItem);
|
||||||
firstRow++;
|
firstRow++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// for whatever reason insertRows doesn't work as I expected with childless items
|
||||||
|
// so just append all the new maps instead
|
||||||
|
else {
|
||||||
|
for (QString mapName : droppedMaps) {
|
||||||
|
QStandardItem *mapItem = createMapItem(mapName);
|
||||||
|
groupItem->appendRow(mapItem);
|
||||||
|
firstRow++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dragMoveCompleted();
|
emit dragMoveCompleted();
|
||||||
|
@ -189,6 +200,10 @@ void MapGroupModel::updateProject() {
|
||||||
QStringList mapsInGroup;
|
QStringList mapsInGroup;
|
||||||
for (int m = 0; m < groupItem->rowCount(); m++) {
|
for (int m = 0; m < groupItem->rowCount(); m++) {
|
||||||
QStandardItem *mapItem = groupItem->child(m);
|
QStandardItem *mapItem = groupItem->child(m);
|
||||||
|
if (!mapItem) {
|
||||||
|
logError("An error occured while trying to apply updates to map group structure.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
QString mapName = mapItem->data(Qt::UserRole).toString();
|
QString mapName = mapItem->data(Qt::UserRole).toString();
|
||||||
mapsInGroup.append(mapName);
|
mapsInGroup.append(mapName);
|
||||||
mapNames.append(mapName);
|
mapNames.append(mapName);
|
||||||
|
@ -222,10 +237,17 @@ QStandardItem *MapGroupModel::createMapItem(QString mapName, QStandardItem *map)
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStandardItem *MapGroupModel::insertGroupItem(QString groupName) {
|
||||||
|
QStandardItem *group = createGroupItem(groupName, this->groupItems.size());
|
||||||
|
this->root->appendRow(group);
|
||||||
|
this->updateProject();
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
QStandardItem *MapGroupModel::insertMapItem(QString mapName, QString groupName) {
|
QStandardItem *MapGroupModel::insertMapItem(QString mapName, QString groupName) {
|
||||||
QStandardItem *group = this->groupItems[groupName];
|
QStandardItem *group = this->groupItems[groupName];
|
||||||
if (!group) {
|
if (!group) {
|
||||||
return nullptr;
|
group = insertGroupItem(groupName);
|
||||||
}
|
}
|
||||||
QStandardItem *map = createMapItem(mapName);
|
QStandardItem *map = createMapItem(mapName);
|
||||||
group->appendRow(map);
|
group->appendRow(map);
|
||||||
|
|
Loading…
Reference in a new issue