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
2018-10-25 12:15:13 +02:00

80 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#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!
}
}
}