Branch 'dev/resourcemanagement' - 4 commits - incidenceeditor-ng/attendeecomboboxdelegate.cpp incidenceeditor-ng/attendeetablemodel.cpp incidenceeditor-ng/incidenceresource.cpp incidenceeditor-ng/resourcemanagement.cpp incidenceeditor-ng/resourcemanagement.h incidenceeditor-ng/resourcemanagement.ui incidenceeditor-ng/resourcemanagement.ui.save incidenceeditor-ng/tests

Sandro Knauß knauss at kolabsys.com
Tue May 6 11:24:38 CEST 2014


 incidenceeditor-ng/attendeecomboboxdelegate.cpp    |    8 +
 incidenceeditor-ng/attendeetablemodel.cpp          |   12 +-
 incidenceeditor-ng/incidenceresource.cpp           |   89 +--------------------
 incidenceeditor-ng/resourcemanagement.cpp          |   10 +-
 incidenceeditor-ng/resourcemanagement.h            |    8 -
 incidenceeditor-ng/resourcemanagement.ui           |    2 
 incidenceeditor-ng/resourcemanagement.ui.save      |   64 ---------------
 incidenceeditor-ng/tests/resourcemanagment_gui.cpp |    7 -
 8 files changed, 33 insertions(+), 167 deletions(-)

New commits:
commit 6ed9eda1d3cffe9a10ea736be177ac8d615a19a9
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Tue May 6 11:08:28 2014 +0200

    Using KDescendantsProxyModel instead of own written flattener

diff --git a/incidenceeditor-ng/incidenceresource.cpp b/incidenceeditor-ng/incidenceresource.cpp
index 6459194..5969c86 100644
--- a/incidenceeditor-ng/incidenceresource.cpp
+++ b/incidenceeditor-ng/incidenceresource.cpp
@@ -29,6 +29,7 @@
 #endif
 
 #include <KDebug>
+#include <KDescendantsProxyModel>
 #include <KMessageBox>
 
 #include <KCalUtils/Stringify>
@@ -38,86 +39,6 @@
 #include <QCompleter>
 using namespace IncidenceEditorNG;
 
-#include <QStandardItem>
-#include <QAbstractProxyModel>
-#include <QSortFilterProxyModel>
-/* Flatten the TreeModel of Resources */
-class SortProxy : public QAbstractProxyModel
-{
-    Q_OBJECT
-
-public:
-    SortProxy(QObject *parent = 0) : QAbstractProxyModel(parent) {
-
-    }
-
-    void setSourceModel(QAbstractItemModel *model) {
-        QAbstractProxyModel::setSourceModel(model);
-        connect(model, SIGNAL(layoutChanged()),
-                SLOT(slotLayoutChanged())
-               );
-    }
-
-    int rowCount(const QModelIndex &parent) const {
-        return mapping.size();
-    }
-
-    int columnCount(const QModelIndex &) const {
-        return 1;
-    }
-
-    QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const {
-        return indexList.value(row);
-    }
-
-    QModelIndex parent(const QModelIndex &child) const {
-        return QModelIndex();
-    }
-
-    QModelIndex mapToSource(const QModelIndex &proxyIndex) const {
-        if (!proxyIndex.isValid()) {
-            return QModelIndex();
-        }
-        return mapping.key(proxyIndex);
-    }
-
-    QModelIndex mapFromSource(const QModelIndex &sourceIndex) const {
-        if (!sourceIndex.isValid()) {
-            return QModelIndex();
-        }
-        return mapping.value(sourceIndex);
-    }
-
-private slots:
-    void slotLayoutChanged() {
-        indexList.clear();
-        mapping.clear();
-
-        ResourceItem *rootItem = ((ResourceModel*) sourceModel())->getItem(QModelIndex());
-        // go through all parents and childs (first level)
-        for (int i = 0; i < rootItem->childCount(); i++) {
-            ResourceItem *item = rootItem->child(i);
-            QModelIndex parentIndex = ((ResourceModel*) sourceModel())->index(i, 0);
-            QModelIndex proxy = createIndex(indexList.size(), 0, parentIndex.internalPointer());
-            indexList.append(proxy);
-            mapping.insert(QPersistentModelIndex(parentIndex), proxy);
-            for (int j = 0; j < item->childCount(); j++) {
-                QModelIndex index = ((ResourceModel*) sourceModel())->index(j, 0, parentIndex);
-                QModelIndex proxy = createIndex(indexList.size(), 0, index.internalPointer());
-                indexList.append(proxy);
-                mapping.insert(QPersistentModelIndex(index), proxy);
-            }
-        }
-    }
-
-private:
-    /* list of all list indexes
-     * The index of the this list is the same as the row of the model*/
-    QList <QModelIndex> indexList;
-    /* mapping between the list index -> resource index */
-    QMap<QPersistentModelIndex, QPersistentModelIndex> mapping;
-};
-
 #ifdef KDEPIM_MOBILE_UI
 IncidenceResource::IncidenceResource(Ui::EventOrTodoMore *ui)
 #else
@@ -182,8 +103,10 @@ IncidenceResource::IncidenceResource(Ui::EventOrTodoDesktop *ui)
 
     completer = new QCompleter(this);
     ResourceModel *model = new ResourceModel(attrs, this);
-    SortProxy *proxyModel = new SortProxy(this);
-    proxyModel->setSourceModel(model);
+
+    KDescendantsProxyModel *proxyModel = new KDescendantsProxyModel( this );
+    proxyModel->setSourceModel( model );
+
     completer->setModel(proxyModel);
     completer->setWrapAround(false);
     mUi->mNewResource->setCompleter(completer);


commit 6ab99c2596662711278c6e2ea761c695748feb65
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Tue May 6 10:59:15 2014 +0200

    fix oneliner ifs

diff --git a/incidenceeditor-ng/attendeecomboboxdelegate.cpp b/incidenceeditor-ng/attendeecomboboxdelegate.cpp
index 7266e00..21ec3f8 100644
--- a/incidenceeditor-ng/attendeecomboboxdelegate.cpp
+++ b/incidenceeditor-ng/attendeecomboboxdelegate.cpp
@@ -43,8 +43,9 @@ void AttendeeComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex
 {
     AttendeeComboBox *comboBox = static_cast<AttendeeComboBox*>(editor);
     int value = index.model()->data(index, Qt::EditRole).toUInt();
-    if (value >= entries.count())
+    if (value >= entries.count()) {
         value = standardIndex;
+    }
     comboBox->setCurrentIndex(value);
 }
 
@@ -65,8 +66,9 @@ void AttendeeComboBoxDelegate::paint(QPainter *painter, const QStyleOptionViewIt
     int value = index.model()->data(index).toUInt();
     pushButton.rect = option.rect;
     pushButton.features |= QStyleOptionButton::HasMenu;
-    if (value >= entries.count())
+    if (value >= entries.count()) {
         value = standardIndex;
+    }
     pushButton.icon = entries[value].first;
 
     QApplication::style()->drawControl(QStyle::CE_PushButton, &pushButton, painter);
@@ -100,4 +102,4 @@ void AttendeeLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel
 void AttendeeLineEditDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
 {
     editor->setGeometry(option.rect);
-}
\ No newline at end of file
+}
diff --git a/incidenceeditor-ng/attendeetablemodel.cpp b/incidenceeditor-ng/attendeetablemodel.cpp
index 0e86f77..b947aac 100644
--- a/incidenceeditor-ng/attendeetablemodel.cpp
+++ b/incidenceeditor-ng/attendeetablemodel.cpp
@@ -26,19 +26,22 @@ int AttendeeTableModel::columnCount(const QModelIndex &/*parent*/) const
 
 Qt::ItemFlags AttendeeTableModel::flags(const QModelIndex &index) const
 {
-    if (!index.isValid())
+    if (!index.isValid()) {
         return Qt::ItemIsEnabled;
+    }
 
     return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
 }
 
 QVariant AttendeeTableModel::data(const QModelIndex &index, int role) const
 {
-    if (!index.isValid())
+    if (!index.isValid()) {
         return QVariant();
+    }
 
-    if (index.row() >= attendeeList.size())
+    if (index.row() >= attendeeList.size()) {
         return QVariant();
+    }
 
     if (role == Qt::DisplayRole || role == Qt::EditRole) {
         switch (index.column()) {
@@ -92,8 +95,9 @@ bool AttendeeTableModel::setData(const QModelIndex& index, const QVariant& value
 QVariant AttendeeTableModel::headerData(int section, Qt::Orientation orientation,
                                         int role) const
 {
-    if (role != Qt::DisplayRole)
+    if (role != Qt::DisplayRole) {
         return QVariant();
+    }
 
     if (orientation == Qt::Horizontal) {
         switch (section) {
diff --git a/incidenceeditor-ng/incidenceresource.cpp b/incidenceeditor-ng/incidenceresource.cpp
index 3a61074..6459194 100644
--- a/incidenceeditor-ng/incidenceresource.cpp
+++ b/incidenceeditor-ng/incidenceresource.cpp
@@ -75,14 +75,16 @@ public:
     }
 
     QModelIndex mapToSource(const QModelIndex &proxyIndex) const {
-        if (!proxyIndex.isValid())
+        if (!proxyIndex.isValid()) {
             return QModelIndex();
+        }
         return mapping.key(proxyIndex);
     }
 
     QModelIndex mapFromSource(const QModelIndex &sourceIndex) const {
-        if (!sourceIndex.isValid())
+        if (!sourceIndex.isValid()) {
             return QModelIndex();
+        }
         return mapping.value(sourceIndex);
     }
 


commit 2156260e320c70aba49bd7c4d089760d4d05a66c
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Tue May 6 10:50:33 2014 +0200

    resourceManagement => ResourceManagement

diff --git a/incidenceeditor-ng/incidenceresource.cpp b/incidenceeditor-ng/incidenceresource.cpp
index f96c8d9..3a61074 100644
--- a/incidenceeditor-ng/incidenceresource.cpp
+++ b/incidenceeditor-ng/incidenceresource.cpp
@@ -300,7 +300,7 @@ void IncidenceResource::bookResource()
 
 void IncidenceResource::findResources()
 {
-    resourceManagement* dialog = new resourceManagement();
+    ResourceManagement* dialog = new ResourceManagement();
     dialog->show();
 }
 
@@ -317,4 +317,4 @@ int IncidenceResource::resourcesCount() const
     return 0;
 }
 
-#include "incidenceresource.moc"
\ No newline at end of file
+#include "incidenceresource.moc"
diff --git a/incidenceeditor-ng/resourcemanagement.cpp b/incidenceeditor-ng/resourcemanagement.cpp
index 198310a..48a55d7 100644
--- a/incidenceeditor-ng/resourcemanagement.cpp
+++ b/incidenceeditor-ng/resourcemanagement.cpp
@@ -30,9 +30,9 @@
 
 using namespace IncidenceEditorNG;
 
-resourceManagement::resourceManagement()
+ResourceManagement::ResourceManagement()
 {
-    ui = new Ui::resourceManagement;
+    ui = new Ui::ResourceManagement;
     ui->setupUi(this);
 
     QStringList attrs;
@@ -53,19 +53,19 @@ resourceManagement::resourceManagement()
 
 }
 
-void resourceManagement::slotStartSearch(const QString &text)
+void ResourceManagement::slotStartSearch(const QString &text)
 {
     ((ResourceModel*)ui->treeResults->model())->startSearch(text);
 }
 
-void resourceManagement::slotShowDetails(const QModelIndex & current)
+void ResourceManagement::slotShowDetails(const QModelIndex & current)
 {
     ResourceItem *item = ((ResourceModel*)current.model())->getItem(current);
     showDetails(item->ldapObject());
 }
 
 
-void resourceManagement::showDetails(const KLDAP::LdapObject &obj)
+void ResourceManagement::showDetails(const KLDAP::LdapObject &obj)
 {
     // Clean up formDetails
     QLayoutItem *child;
diff --git a/incidenceeditor-ng/resourcemanagement.h b/incidenceeditor-ng/resourcemanagement.h
index 2ea9cba..3749db6 100644
--- a/incidenceeditor-ng/resourcemanagement.h
+++ b/incidenceeditor-ng/resourcemanagement.h
@@ -34,7 +34,7 @@
 
 namespace Ui
 {
-class resourceManagement;
+class ResourceManagement;
 }
 
 namespace IncidenceEditorNG
@@ -42,11 +42,11 @@ namespace IncidenceEditorNG
 
 class QTreeModel;
 
-class INCIDENCEEDITORS_NG_EXPORT resourceManagement : public KDialog
+class INCIDENCEEDITORS_NG_EXPORT ResourceManagement : public KDialog
 {
     Q_OBJECT
 public:
-    resourceManagement();
+    ResourceManagement();
 
 private:
     /* Shows the details of a resource
@@ -54,7 +54,7 @@ private:
      */
     void showDetails(const KLDAP::LdapObject&);
 
-    Ui::resourceManagement* ui;
+    Ui::ResourceManagement* ui;
 
     QItemSelectionModel *selectionModel;
 
diff --git a/incidenceeditor-ng/resourcemanagement.ui b/incidenceeditor-ng/resourcemanagement.ui
index e92bb33..38002e1 100644
--- a/incidenceeditor-ng/resourcemanagement.ui
+++ b/incidenceeditor-ng/resourcemanagement.ui
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
- <class>resourceManagement</class>
+ <class>ResourceManagement</class>
  <widget class="QWidget" name="resourceManagement">
   <property name="geometry">
    <rect>
diff --git a/incidenceeditor-ng/tests/resourcemanagment_gui.cpp b/incidenceeditor-ng/tests/resourcemanagment_gui.cpp
index 6c9972a..a991ed8 100644
--- a/incidenceeditor-ng/tests/resourcemanagment_gui.cpp
+++ b/incidenceeditor-ng/tests/resourcemanagment_gui.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2013 Sandro Knauß <knauss at kolabsys.com>
+/* Copyright 2014 Sandro Knauß <knauss at kolabsys.com>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -28,15 +28,14 @@ using namespace IncidenceEditorNG;
 
 int main (int argc, char **argv)
 {
-  KCmdLineArgs::init(argc, argv, "viewertest_gui", 0, ki18n("Viewertest_Gui"),
+  KCmdLineArgs::init(argc, argv, "resourcemanagement_gui", 0, ki18n("resourcemanagement_Gui"),
                      "1.0", ki18n("Test for resourceManagement"));
 
   KCmdLineArgs::addStdCmdLineOptions();
 
   KApplication app;
-  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
 
-  resourceManagement* dialog = new resourceManagement();
+  ResourceManagement* dialog = new ResourceManagement();
 
   dialog->show();
 


commit da36532c3059991be433b7d64c01777b762ff71d
Author: Sandro Knauß <knauss at kolabsys.com>
Date:   Tue May 6 10:45:00 2014 +0200

    deleted *.save files out of repo

diff --git a/incidenceeditor-ng/resourcemanagement.ui.save b/incidenceeditor-ng/resourcemanagement.ui.save
deleted file mode 100644
index 57d07a6..0000000
--- a/incidenceeditor-ng/resourcemanagement.ui.save
+++ /dev/null
@@ -1,64 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>resourceManagement</class>
- <widget class="QWidget" name="resourceManagement">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>714</width>
-    <height>412</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
-  <widget class="QWidget" name="">
-   <property name="geometry">
-    <rect>
-     <x>1</x>
-     <y>1</y>
-     <width>711</width>
-     <height>401</height>
-    </rect>
-   </property>
-   <layout class="QHBoxLayout" name="horizontalLayout">
-    <item>
-     <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
-      <property name="spacing">
-       <number>2</number>
-      </property>
-      <item>
-       <widget class="QLineEdit" name="resourceSearch"/>
-      </item>
-      <item>
-       <widget class="QListView" name="resourceResults"/>
-      </item>
-     </layout>
-    </item>
-    <item>
-     <layout class="QVBoxLayout" name="verticalLayout_2">
-      <property name="spacing">
-       <number>2</number>
-      </property>
-      <item>
-       <widget class="QTextEdit" name="resourceDetails"/>
-      </item>
-      <item>
-       <widget class="QWidget" name="resourceCalender" native="true">
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-       </widget>
-      </item>
-     </layout>
-    </item>
-   </layout>
-  </widget>
- </widget>
- <resources/>
- <connections/>
-</ui>




More information about the commits mailing list