diff --git a/lib/db_base.cpp b/lib/db_base.cpp index 8eaedd3a..1d977381 100644 --- a/lib/db_base.cpp +++ b/lib/db_base.cpp @@ -684,3 +684,8 @@ int db_base::exportFlags(const QModelIndexList &indexes) const disabled_flags |= F_MULTI; return disabled_flags; } + +void db_base::setSelected(const QVariant &v) +{ + selected = v; +} diff --git a/lib/db_base.h b/lib/db_base.h index a47257f6..beb91807 100644 --- a/lib/db_base.h +++ b/lib/db_base.h @@ -44,6 +44,7 @@ class db_base: public QAbstractItemModel bool treeview; pki_base *rootItem; pki_base *treeItem; + QVariant selected; public: void restart_timer(); @@ -137,6 +138,7 @@ class db_base: public QAbstractItemModel void columnResetDefaults(); void sectionResized(int i, int, int newSize); void sortIndicatorChanged(int, Qt::SortOrder); + void setSelected(const QVariant &v); signals: void resetHeader() const; diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index 292a64be..0c873e5a 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -339,15 +339,6 @@ pki_base *db_x509::insert(pki_base *item) return insertPKI(cert); } -pki_x509 *db_x509::get1SelectedCert() -{ - QModelIndexList indexes = mainwin->certView->getSelectedIndexes(); - QModelIndex index; - if (indexes.count()) - index = indexes[0]; - return fromIndex(index); -} - void db_x509::markRequestSigned(pki_x509req *req, pki_x509 *cert) { if (!req || !cert) @@ -381,8 +372,9 @@ void db_x509::newItem() { NewX509 *dlg = new NewX509(); dlg->setCert(); - pki_x509 *sigcert = get1SelectedCert(); - dlg->defineSigner((pki_x509*)sigcert, true); + pki_x509 *sigcert = Store.lookupPki(selected); + qDebug() << "SIGCERT" << (sigcert ? sigcert->getIntName() : "NULLL"); + dlg->defineSigner(sigcert, true); if (dlg->exec()) { newCert(dlg); } @@ -392,7 +384,8 @@ void db_x509::newItem() void db_x509::newCert(pki_x509req *req) { NewX509 *dlg = new NewX509(); - pki_x509 *sigcert = get1SelectedCert(); + pki_x509 *sigcert = Store.lookupPki(selected); + qDebug() << "SIGCERT" << (sigcert ? sigcert->getIntName() : "NULLL"); dlg->setCert(); dlg->defineRequest(req); dlg->defineSigner(sigcert, true); diff --git a/lib/db_x509.h b/lib/db_x509.h index c5a6490d..2395822d 100644 --- a/lib/db_x509.h +++ b/lib/db_x509.h @@ -24,7 +24,6 @@ class db_x509: public db_x509super Q_OBJECT protected: - pki_x509 *get1SelectedCert(); dbheaderList getHeaders(); void dereferenceIssuer(); diff --git a/lib/func.h b/lib/func.h index 686aea81..995e2868 100644 --- a/lib/func.h +++ b/lib/func.h @@ -21,9 +21,7 @@ #define IS_GUI_APP (is_gui_app) class Validity; -class MainWindow; class QPixmap; -extern MainWindow *mainwin; extern bool is_gui_app; typedef struct asn1_object_st ASN1_OBJECT; diff --git a/widgets/XcaTreeView.cpp b/widgets/XcaTreeView.cpp index 71a67cfe..2ece5209 100644 --- a/widgets/XcaTreeView.cpp +++ b/widgets/XcaTreeView.cpp @@ -119,6 +119,10 @@ void XcaTreeView::setModel(QAbstractItemModel *model) basemodel, SLOT(sortIndicatorChanged(int,Qt::SortOrder))); connect(basemodel, SIGNAL(columnsContentChanged()), this, SLOT(columnsChanged())); + connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, + const QModelIndex &)), + this, SLOT(itemSelectionChanged(const QModelIndex &, + const QModelIndex &))); basemodel->initHeaderView(header()); } @@ -140,6 +144,20 @@ QModelIndex XcaTreeView::getProxyIndex(const QModelIndex &index) return proxy->mapFromSource(index); } +void XcaTreeView::itemSelectionChanged(const QModelIndex &m, const QModelIndex &) +{ + QModelIndex index = getIndex(m); + QVariant v; + qDebug() << "selectionChanged()" << index.isValid() << index.row() << index.column(); + if (m.isValid()) { + pki_base *pki = db_base::fromIndex(index); + if (pki) + v = pki->getSqlItemId(); + } + if (basemodel) + basemodel->setSelected(v); +} + QModelIndexList XcaTreeView::getSelectedIndexes() { QModelIndexList list; diff --git a/widgets/XcaTreeView.h b/widgets/XcaTreeView.h index 2b7ca187..a3843784 100644 --- a/widgets/XcaTreeView.h +++ b/widgets/XcaTreeView.h @@ -84,5 +84,6 @@ class XcaTreeView: public QTreeView void showItem(pki_base *); void showItem(const QModelIndex &index); void showItem(const QString &name); + void itemSelectionChanged(const QModelIndex &m, const QModelIndex &); }; #endif