functions to remove map groups and map sections
This commit is contained in:
parent
74e4e2647c
commit
879bb44bc0
5 changed files with 77 additions and 1 deletions
|
@ -394,6 +394,9 @@ private:
|
|||
void mapListAddGroup();
|
||||
void mapListAddLayout();
|
||||
void mapListAddArea();
|
||||
void mapListRemoveGroup();
|
||||
void mapListRemoveArea();
|
||||
void mapListRemoveLayout();
|
||||
|
||||
void displayMapProperties();
|
||||
void checkToolButtons();
|
||||
|
|
|
@ -77,6 +77,7 @@ public:
|
|||
|
||||
QStandardItem *insertGroupItem(QString groupName);
|
||||
QStandardItem *insertMapItem(QString mapName, QString groupName);
|
||||
void removeGroup(int groupIndex);
|
||||
|
||||
QStandardItem *getItem(const QModelIndex &index) const;
|
||||
QModelIndex indexOfMap(QString mapName);
|
||||
|
@ -119,6 +120,7 @@ public:
|
|||
|
||||
QStandardItem *insertAreaItem(QString areaName);
|
||||
QStandardItem *insertMapItem(QString mapName, QString areaName, int groupIndex);
|
||||
void removeArea(int groupIndex);
|
||||
|
||||
QStandardItem *getItem(const QModelIndex &index) const;
|
||||
QModelIndex indexOfMap(QString mapName);
|
||||
|
|
|
@ -1459,6 +1459,8 @@ void MainWindow::mapListAddArea() {
|
|||
}
|
||||
|
||||
void MainWindow::mapListAddItem() {
|
||||
if (!this->editor || !this->editor->project) return;
|
||||
|
||||
switch (this->ui->mapListContainer->currentIndex()) {
|
||||
case 0:
|
||||
this->mapListAddGroup();
|
||||
|
@ -1472,8 +1474,61 @@ void MainWindow::mapListAddItem() {
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::mapListRemoveGroup() {
|
||||
QItemSelectionModel *selectionModel = this->ui->mapList->selectionModel();
|
||||
if (selectionModel->hasSelection()) {
|
||||
QModelIndexList selectedIndexes = selectionModel->selectedRows();
|
||||
for (QModelIndex proxyIndex : selectedIndexes) {
|
||||
QModelIndex index = this->groupListProxyModel->mapToSource(proxyIndex);
|
||||
QStandardItem *item = this->mapGroupModel->getItem(index)->child(index.row(), index.column());
|
||||
if (!item) continue;
|
||||
QString type = item->data(MapListRoles::TypeRole).toString();
|
||||
if (type == "map_group" && !item->hasChildren()) {
|
||||
QString groupName = item->data(Qt::UserRole).toString();
|
||||
// delete empty group
|
||||
this->mapGroupModel->removeGroup(index.row());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::mapListRemoveArea() {
|
||||
QItemSelectionModel *selectionModel = this->ui->areaList->selectionModel();
|
||||
if (selectionModel->hasSelection()) {
|
||||
QModelIndexList selectedIndexes = selectionModel->selectedRows();
|
||||
for (QModelIndex proxyIndex : selectedIndexes) {
|
||||
QModelIndex index = this->areaListProxyModel->mapToSource(proxyIndex);
|
||||
QStandardItem *item = this->mapAreaModel->getItem(index)->child(index.row(), index.column());
|
||||
if (!item) continue;
|
||||
QString type = item->data(MapListRoles::TypeRole).toString();
|
||||
if (type == "map_section" && !item->hasChildren()) {
|
||||
QString groupName = item->data(Qt::UserRole).toString();
|
||||
// delete empty section
|
||||
this->mapAreaModel->removeArea(index.row());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::mapListRemoveLayout() {
|
||||
// TODO: consider this
|
||||
// do nothing, for now at least
|
||||
}
|
||||
|
||||
void MainWindow::mapListRemoveItem() {
|
||||
// !TODO
|
||||
if (!this->editor || !this->editor->project) return;
|
||||
|
||||
switch (this->ui->mapListContainer->currentIndex()) {
|
||||
case 0:
|
||||
this->mapListRemoveGroup();
|
||||
break;
|
||||
case 1:
|
||||
this->mapListRemoveArea();
|
||||
break;
|
||||
case 2:
|
||||
this->mapListRemoveLayout();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction) {
|
||||
|
|
|
@ -712,6 +712,8 @@ void Project::saveMapSections() {
|
|||
longestLength = label.size();
|
||||
}
|
||||
|
||||
longestLength += 1;
|
||||
|
||||
// mapSectionValueToName
|
||||
for (int value : this->mapSectionValueToName.keys()) {
|
||||
QString line = QString("#define %1 0x%2\n")
|
||||
|
|
|
@ -244,6 +244,11 @@ QStandardItem *MapGroupModel::insertGroupItem(QString groupName) {
|
|||
return group;
|
||||
}
|
||||
|
||||
void MapGroupModel::removeGroup(int groupIndex) {
|
||||
this->removeRow(groupIndex);
|
||||
this->updateProject();
|
||||
}
|
||||
|
||||
QStandardItem *MapGroupModel::insertMapItem(QString mapName, QString groupName) {
|
||||
QStandardItem *group = this->groupItems[groupName];
|
||||
if (!group) {
|
||||
|
@ -412,6 +417,11 @@ QStandardItem *MapAreaModel::insertMapItem(QString mapName, QString areaName, in
|
|||
return map;
|
||||
}
|
||||
|
||||
void MapAreaModel::removeArea(int areaIndex) {
|
||||
this->removeRow(areaIndex);
|
||||
this->project->mapSectionNameToValue.remove(this->project->mapSectionValueToName.take(areaIndex));
|
||||
}
|
||||
|
||||
void MapAreaModel::initialize() {
|
||||
this->areaItems.clear();
|
||||
this->mapItems.clear();
|
||||
|
@ -454,6 +464,8 @@ QModelIndex MapAreaModel::indexOfMap(QString mapName) {
|
|||
}
|
||||
|
||||
QVariant MapAreaModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid()) return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
|
||||
|
@ -600,6 +612,8 @@ QModelIndex LayoutTreeModel::indexOfLayout(QString layoutName) {
|
|||
}
|
||||
|
||||
QVariant LayoutTreeModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid()) return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
|
||||
|
|
Loading…
Reference in a new issue