/* * © 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 #include #include #include 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! } } }