Commit a3236cabc9ad0d2d792c7e99c754068b807182b5
1 parent
153ba3ef
added option to EmptyGallery to filter based on file extension
Showing
1 changed file
with
11 additions
and
0 deletions
openbr/plugins/gallery.cpp
| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 | * limitations under the License. * |
| 15 | 15 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 16 | 16 | |
| 17 | +#include <QRegularExpression> | |
| 17 | 18 | #include <QtConcurrentRun> |
| 18 | 19 | #ifndef BR_EMBEDDED |
| 19 | 20 | #include <QNetworkAccessManager> |
| ... | ... | @@ -128,10 +129,13 @@ BR_REGISTER(Gallery, galGallery) |
| 128 | 129 | * \ingroup galleries |
| 129 | 130 | * \brief Reads/writes templates to/from folders. |
| 130 | 131 | * \author Josh Klontz \cite jklontz |
| 132 | + * \param regexp An optional regular expression to match against the files extension. | |
| 131 | 133 | */ |
| 132 | 134 | class EmptyGallery : public Gallery |
| 133 | 135 | { |
| 134 | 136 | Q_OBJECT |
| 137 | + Q_PROPERTY(QString regexp READ get_regexp WRITE set_regexp RESET reset_regexp STORED false) | |
| 138 | + BR_PROPERTY(QString, regexp, "") | |
| 135 | 139 | |
| 136 | 140 | void init() |
| 137 | 141 | { |
| ... | ... | @@ -160,6 +164,13 @@ class EmptyGallery : public Gallery |
| 160 | 164 | foreach (const QString &fileName, QtUtils::getFiles(file.name, false)) |
| 161 | 165 | templates.append(File(fileName, dir.dirName())); |
| 162 | 166 | |
| 167 | + if (!regexp.isEmpty()) { | |
| 168 | + const QRegularExpression re(regexp); | |
| 169 | + for (int i=templates.size()-1; i>=0; i--) | |
| 170 | + if (!re.match(templates[i].file.suffix()).hasMatch()) | |
| 171 | + templates.removeAt(i); | |
| 172 | + } | |
| 173 | + | |
| 163 | 174 | return templates; |
| 164 | 175 | } |
| 165 | 176 | ... | ... |