mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Drop global pointer to mainwin by fixing its last user db_x509
Instead of querying the view about the selected item, let the view store the current item in the model.
This commit is contained in:
parent
42b76418fb
commit
3a73697406
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<pki_x509>(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<pki_x509>(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<pki_x509>(selected);
|
||||
qDebug() << "SIGCERT" << (sigcert ? sigcert->getIntName() : "NULLL");
|
||||
dlg->setCert();
|
||||
dlg->defineRequest(req);
|
||||
dlg->defineSigner(sigcert, true);
|
||||
|
||||
@ -24,7 +24,6 @@ class db_x509: public db_x509super
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
pki_x509 *get1SelectedCert();
|
||||
dbheaderList getHeaders();
|
||||
void dereferenceIssuer();
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user