From 56c6df6c90182baa550dccd2cf588d7b040259eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Hohnst=C3=A4dt?= Date: Sat, 19 Jun 2021 13:18:48 +0200 Subject: [PATCH] editComment: Move Gui elements to widgets/XcaTreeView Another step to separate GUI from functionality --- lib/db_base.cpp | 28 +++------------------------- lib/db_base.h | 1 - widgets/XcaTreeView.cpp | 22 ++++++++++++++++++++-- 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/lib/db_base.cpp b/lib/db_base.cpp index 98be5cea..1045ea33 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -8,6 +8,8 @@ #include "db_base.h" #include "func.h" #include "exception.h" +#include "XcaWarningCore.h" + #include #include #include @@ -18,13 +20,9 @@ #include #warning drop UI dependencies -#include "widgets/XcaWarning.h" #include "widgets/ImportMulti.h" -#include "widgets/XcaDialog.h" - -#include "ui_ItemProperties.h" +#include "widgets/XcaWarning.h" #include "ui_ImportMulti.h" -#include "ui_XcaDialog.h" void db_base::restart_timer() { @@ -630,26 +628,6 @@ void db_base::timerEvent(QTimerEvent *event) } } -void db_base::editComment(const QModelIndex &index) -{ - pki_base *item = fromIndex(index); - if (!index.isValid() || !item) - return; - - QWidget *w = new QWidget(NULL); - Ui::ItemProperties *prop = new Ui::ItemProperties(); - prop->setupUi(w); - prop->comment->setPlainText(item->getComment()); - prop->name->setText(item->getIntName()); - prop->source->setText(item->pki_source_name()); - prop->insertionDate->setText(item->getInsertionDate().toPretty()); - XcaDialog *d = new XcaDialog(nullptr, item->getType(), w, - tr("Item properties"), QString(), "itemproperties"); - if (d->exec()) - updateItem(item, prop->name->text(), prop->comment->toPlainText()); - delete d; -} - void db_base::load_default(load_base &load) { QString s; diff --git a/lib/db_base.h b/lib/db_base.h index 992bccbf..93cd45f4 100644 --- a/lib/db_base.h +++ b/lib/db_base.h @@ -128,7 +128,6 @@ class db_base: public QAbstractItemModel void deletePKI(QModelIndex idx); QMimeData *mimeData(const QModelIndexList &indexes) const; - void editComment(const QModelIndex &index); void emitDataChanged(pki_base *pki); bool containsType(enum pki_type t) const; void writeVcalendar(XFile &file, QStringList vcal) const; diff --git a/widgets/XcaTreeView.cpp b/widgets/XcaTreeView.cpp index 946a66ee..3a21f5f4 100644 --- a/widgets/XcaTreeView.cpp +++ b/widgets/XcaTreeView.cpp @@ -18,8 +18,11 @@ #include "XcaProxyModel.h" #include "MainWindow.h" #include "XcaWarning.h" +#include "XcaDialog.h" #include "XcaApplication.h" +#include "ui_ItemProperties.h" + XcaTreeView::XcaTreeView(QWidget *parent) :QTreeView(parent) { @@ -282,8 +285,23 @@ void XcaTreeView::doubleClick(const QModelIndex &m) void XcaTreeView::editComment() { - if (basemodel) - basemodel->editComment(currentIndex()); + pki_base *item = db_base::fromIndex(currentIndex()); + if (!basemodel || !item) + return; + + QWidget *w = new QWidget(nullptr); + Ui::ItemProperties *prop = new Ui::ItemProperties(); + prop->setupUi(w); + prop->comment->setPlainText(item->getComment()); + prop->name->setText(item->getIntName()); + prop->source->setText(item->pki_source_name()); + prop->insertionDate->setText(item->getInsertionDate().toPretty()); + XcaDialog *d = new XcaDialog(this, item->getType(), w, + tr("Item properties"), QString(), "itemproperties"); + if (d->exec()) + basemodel->updateItem(item, prop->name->text(), + prop->comment->toPlainText()); + delete d; } void XcaTreeView::pem2clipboard()