summaryrefslogtreecommitdiffstats
path: root/src/storemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/storemodel.cpp')
-rw-r--r--src/storemodel.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/storemodel.cpp b/src/storemodel.cpp
new file mode 100644
index 00000000..0b45eb10
--- /dev/null
+++ b/src/storemodel.cpp
@@ -0,0 +1,84 @@
+#include "storemodel.h"
+
+/**
+ * @brief StoreModel::StoreModel
+ * SubClass of QSortFilterProxyModel via
+ * http://www.qtcentre.org/threads/46471-QTreeView-Filter
+ */
+StoreModel::StoreModel() { fs = NULL; }
+
+/**
+ * @brief StoreModel::filterAcceptsRow should row be shown, wrapper for
+ * StoreModel::ShowThis method.
+ * @param sourceRow
+ * @param sourceParent
+ * @return
+ */
+bool StoreModel::filterAcceptsRow(int sourceRow,
+ const QModelIndex &sourceParent) const {
+ QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
+ return ShowThis(index);
+}
+
+/**
+ * @brief StoreModel::ShowThis should a row be shown, based on our search
+ * criteria.
+ * @param index
+ * @return
+ */
+bool StoreModel::ShowThis(const QModelIndex index) const {
+ bool retVal = false;
+ if (fs == NULL)
+ return retVal;
+ // Gives you the info for number of childs with a parent
+ if (sourceModel()->rowCount(index) > 0) {
+ for (int nChild = 0; nChild < sourceModel()->rowCount(index); ++nChild) {
+ QModelIndex childIndex = sourceModel()->index(nChild, 0, index);
+ if (!childIndex.isValid())
+ break;
+ retVal = ShowThis(childIndex);
+ if (retVal)
+ break;
+ }
+ } else {
+ QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent());
+ QString path = fs->filePath(useIndex);
+ path = QDir(store).relativeFilePath(path);
+ path.replace(QRegExp("\\.gpg$"), "");
+ retVal = path.contains(filterRegExp());
+ }
+ return retVal;
+}
+
+/**
+ * @brief StoreModel::setModelAndStore update the source model and store.
+ * @param sourceModel
+ * @param passStore
+ */
+void StoreModel::setModelAndStore(QFileSystemModel *sourceModel,
+ QString passStore) {
+ fs = sourceModel;
+ store = passStore;
+}
+
+/**
+ * @brief StoreModel::data don't show the .gpg at the end of a file.
+ * @param index
+ * @param role
+ * @return
+ */
+QVariant StoreModel::data(const QModelIndex &index, int role) const {
+ if (!index.isValid())
+ return QVariant();
+
+ QVariant initial_value;
+ initial_value = QSortFilterProxyModel::data(index, role);
+
+ if (role == Qt::DisplayRole) {
+ QString name = initial_value.toString();
+ name.replace(QRegExp("\\.gpg$"), "");
+ initial_value.setValue(name);
+ }
+
+ return initial_value;
+}