diff src/includeemptysortmodel.cpp @ 88:3916cb3c9105

Add new FilterSort model that allows to include empty values
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 19 Jun 2015 14:26:16 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/includeemptysortmodel.cpp	Fri Jun 19 14:26:16 2015 +0200
@@ -0,0 +1,22 @@
+/* Copyright (C) 2015 by ETH Zürich
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=2)
+ * and comes with ABSOLUTELY NO WARRANTY!
+ * See LICENSE.txt for details.
+ */
+#include "includeemptysortmodel.h"
+
+bool IncludeEmptySortModel::filterAcceptsRow(int row, const QModelIndex &parent) const
+{
+    bool parentAcceptsRow = QSortFilterProxyModel::filterAcceptsRow(row, parent);
+    if (!mIncludeEmpty || parentAcceptsRow) {
+        return parentAcceptsRow;
+    }
+
+    QModelIndex source_index = sourceModel()->index(row, filterKeyColumn(), parent);
+    if (!source_index.isValid()) // the column may not exist
+        return true;
+    QString key = sourceModel()->data(source_index).toString();
+    return key.isEmpty();
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)