diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2014-08-17 00:25:44 +0200 |
---|---|---|
committer | Anne Jan Brouwer <ajbrouwer@totalactivemedia.nl> | 2014-08-17 00:25:44 +0200 |
commit | e049351b144fa1addee50b704469e5974d523b78 (patch) | |
tree | d55485e9a66ac0c4ce5edcc4326d59833ec84977 | |
parent | 4ff5838d84555e314d99916b31f4599e2f9343a7 (diff) |
regexp power
-rw-r--r-- | mainwindow.cpp | 5 | ||||
-rw-r--r-- | resources.qrc | 4 | ||||
-rw-r--r-- | storemodel.cpp | 32 | ||||
-rw-r--r-- | storemodel.h | 2 |
4 files changed, 34 insertions, 9 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp index 8882aca8..61434024 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -171,9 +171,8 @@ void MainWindow::on_treeView_clicked(const QModelIndex &index) currentAction = GPG; QString filePath = model.filePath(proxyModel.mapToSource(index)); QString passFile = filePath; - passFile.replace(".gpg", ""); - passFile.replace(passStore, ""); -// ui->lineEdit->setText(passFile); + passFile.replace(QRegExp("\\.gpg$"), ""); + passFile.replace(QRegExp("^" + passStore), ""); if (model.fileInfo(proxyModel.mapToSource(index)).isFile()){ if (usePass) { executePass(passFile); diff --git a/resources.qrc b/resources.qrc index b9b3a90a..5171bf6f 100644 --- a/resources.qrc +++ b/resources.qrc @@ -14,9 +14,5 @@ <file>artwork/icon.ico</file> <file>artwork/icon.png</file> <file>artwork/icon.svg</file> - <file>localization/localization_pl_PL.qm</file> - <file>localization/localization_pl_PL.ts</file> - <file>localization/localization_sv_SE.qm</file> - <file>localization/localization_sv_SE.ts</file> </qresource> </RCC> diff --git a/storemodel.cpp b/storemodel.cpp index 7e889d3f..213ba8c3 100644 --- a/storemodel.cpp +++ b/storemodel.cpp @@ -48,8 +48,8 @@ bool StoreModel::ShowThis(const QModelIndex index) const { QModelIndex useIndex = sourceModel()->index(index.row(), 0, index.parent()); QString path = fs->filePath(useIndex); - path.replace(".gpg", ""); - path.replace(store, ""); + path.replace(QRegExp("\\.gpg$"), ""); + path.replace(QRegExp("^" + store), ""); if ( ! path.contains(filterRegExp())) { retVal = false; @@ -62,7 +62,35 @@ bool StoreModel::ShowThis(const QModelIndex index) const return retVal; } +/** + * @brief StoreModel::setModelAndStore + * @param sourceModel + * @param passStore + */ void StoreModel::setModelAndStore(QFileSystemModel *sourceModel, QString passStore) { fs = sourceModel; store = passStore; } + +/** + * @brief StoreModel::data + * @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; +} diff --git a/storemodel.h b/storemodel.h index cad3c8de..0f7488ec 100644 --- a/storemodel.h +++ b/storemodel.h @@ -3,6 +3,7 @@ #include <QSortFilterProxyModel> #include <QFileSystemModel> +#include <QRegExp> class StoreModel : public QSortFilterProxyModel { @@ -17,6 +18,7 @@ public: bool filterAcceptsRow(int, const QModelIndex &) const; bool ShowThis(const QModelIndex) const; void setModelAndStore(QFileSystemModel *sourceModel, QString passStore); + QVariant data(const QModelIndex &index, int role) const; }; #endif // STOREMODEL_H |