This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/params/MetaEditWidget.cpp
root e5e19779d5 worked on android port
opengl1 -> es
2018-01-31 17:15:11 +01:00

70 lines
1.8 KiB
C++

#include "../fixC11.h"
#include "MetaEditWidget.h"
#include "MetaEditModel.h"
#include <QTableView>
#include <QGridLayout>
#include <QKeyEvent>
#include <QPushButton>
MetaEditWidget::MetaEditWidget(Floorplan::Meta* meta) : QWidget(nullptr), metaOrig(meta) {
// local copy. for the abort button [orig is unchanged]
metaCopy.params = metaOrig->params;
QGridLayout* lay = new QGridLayout(this);
tbl = new QTableView();
lay->addWidget(tbl, 0, 0, 1, 3);
model = new MetaEditModel();
model->setSource(&metaCopy); // we edit the copy
tbl->setModel(model);
tbl->setSelectionBehavior(QAbstractItemView::SelectRows);
tbl->setSelectionMode(QAbstractItemView::SingleSelection);
// events
QPushButton* btnAdd = new QPushButton("add entry");
lay->addWidget(btnAdd, 1, 0);
btnAdd->connect(btnAdd, &QPushButton::clicked, [this] (const bool) {
model->addEntry();
});
btnAdd->setToolTip("add a new, empty entry. delete an entry using the keyboard");
QPushButton* btnCancel = new QPushButton("abort");
lay->addWidget(btnCancel, 1, 1);
btnCancel->connect(btnCancel, &QPushButton::clicked, [this] (const bool) {
// do not apply changes. juts close
close();
});
btnCancel->setToolTip("close the dialog without committing the changes");
QPushButton* btnOK = new QPushButton("OK");
lay->addWidget(btnOK, 1, 2);
btnOK->connect(btnOK, &QPushButton::clicked, [this] (const bool) {
metaOrig->params = metaCopy.params; // apply changed
close();
});
btnOK->setToolTip("commit the changes and close the dialog");
// sizing
resize(500,400);
}
void MetaEditWidget::keyPressEvent(QKeyEvent* e) {
if (e->key() == Qt::Key_Delete) {
QModelIndexList indices = tbl->selectionModel()->selectedIndexes();
for (const QModelIndex& idx : indices) {
model->deleteEntry(idx.row());
break; // the list contains one entry per column!
}
}
}