changeset 348:e6aa82466420

Use the table item delegate for certificates and make the model editable.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 10 Apr 2014 14:14:56 +0200
parents dde533ba4fcc
children a49766196a7d b0a274f4f9e2
files ui/CMakeLists.txt ui/administratorwindow.cpp ui/certificatetablemodel.cpp ui/certificatetablemodel.h
diffstat 4 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ui/CMakeLists.txt	Thu Apr 10 14:13:34 2014 +0200
+++ b/ui/CMakeLists.txt	Thu Apr 10 14:14:56 2014 +0200
@@ -31,6 +31,7 @@
     ${CMAKE_CURRENT_SOURCE_DIR}/administrator.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/administratorwindow.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/certificatetablemodel.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/certificatetabledelegate.cpp
     ${CERTIFICATELIST_SOURCES}
 )
 
--- a/ui/administratorwindow.cpp	Thu Apr 10 14:13:34 2014 +0200
+++ b/ui/administratorwindow.cpp	Thu Apr 10 14:14:56 2014 +0200
@@ -15,6 +15,8 @@
 #include <QHeaderView>
 #include <QFileDialog>
 
+#include "certificatetabledelegate.h"
+
 AdministratorWindow::AdministratorWindow() {
     createActions();
     createMenuBar();
@@ -61,8 +63,10 @@
     QGroupBox *certBox = new QGroupBox(tr("Managed Certificates"));
     certificateView = new QTableView;
     certificateModel = new CertificateTabelModel();
+    CertificateTableDelegate *delegate = new CertificateTableDelegate(certificateView);
     certificateView->setModel(certificateModel);
-    certificateView->setColumnWidth(0, 60);
+    certificateView->setItemDelegate(delegate);
+    certificateView->setColumnWidth(0, 50);
     certificateView->setColumnWidth(2, 130);
     certificateView->setColumnWidth(3, 130);
     certificateView->setColumnWidth(4, 200);
--- a/ui/certificatetablemodel.cpp	Thu Apr 10 14:13:34 2014 +0200
+++ b/ui/certificatetablemodel.cpp	Thu Apr 10 14:14:56 2014 +0200
@@ -42,6 +42,13 @@
     return QVariant();
 }
 
+bool CertificateTabelModel::setData(const QModelIndex &index,
+    const QVariant &value, int role)
+{
+    //TODO
+    return true;
+}
+
 QVariant CertificateTabelModel::headerData(int section,
         Qt::Orientation orientation, int role) const
 {
@@ -61,4 +68,14 @@
     return header.size();
 }
 
+Qt::ItemFlags CertificateTabelModel::flags(const QModelIndex &index) const
+{
+    if (!index.isValid ())
+        return Qt::ItemIsSelectable;
 
+    if (index.column() == 0) {
+        return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
+    }
+
+    return QAbstractTableModel::flags(index);
+}
--- a/ui/certificatetablemodel.h	Thu Apr 10 14:13:34 2014 +0200
+++ b/ui/certificatetablemodel.h	Thu Apr 10 14:14:56 2014 +0200
@@ -22,8 +22,12 @@
     int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+    bool setData(const QModelIndex &index, const QVariant &value,
+        int role = Qt::EditRole);
     QVariant headerData(int section, Qt::Orientation orientation,
-            int role = Qt::DisplayRole) const;
+        int role = Qt::DisplayRole) const;
+
+    Qt::ItemFlags flags(const QModelIndex &index) const;
 
 private:
     QList<Certificate> certificates;

http://wald.intevation.org/projects/trustbridge/