digiKam
rule.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2010-05-01
7  * Description : an abstract rule class
8  *
9  * Copyright (C) 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_RULE_H
25 #define DIGIKAM_RULE_H
26 
27 // Local includes
28 
29 #include "parseresults.h"
30 #include "parsesettings.h"
31 #include "token.h"
32 
33 class QAction;
34 class QMenu;
35 class QPushButton;
36 class QString;
37 
38 namespace Digikam
39 {
40 
41 class Rule : public QObject
42 {
43  Q_OBJECT
44 
45 public:
46 
47  enum IconType
48  {
49  Action = 0,
50  Dialog
51  };
52 
53 public:
54 
55  explicit Rule(const QString& name);
56  Rule(const QString& name, const QString& icon);
57  ~Rule() override;
58 
79  QRegularExpression& regExp() const;
80 
81  QString description() const;
82  QPixmap icon(Rule::IconType type = Rule::Action) const;
83 
87  TokenList& tokens() const;
88 
96  QPushButton* registerButton(QWidget* parent);
97 
105  QAction* registerMenu(QMenu* parent);
106 
110  bool useTokenMenu() const;
111 
116  bool isValid() const;
117 
121  virtual void reset();
122 
129  static QString escapeToken(const QString& token);
130 
131  ParseResults parse(ParseSettings& settings);
132 
133 Q_SIGNALS:
134 
135  void signalTokenTriggered(const QString&);
136 
137 protected:
138 
145  virtual QString parseOperation(ParseSettings& settings, const QRegularExpressionMatch &match) = 0;
146 
154  bool addToken(const QString& id, const QString& description, const QString& actionName = QString());
155 
156  void setRegExp(const QRegularExpression& regExp);
157  void setDescription(const QString& desc);
158  void setIcon(const QString& pixmap);
159 
166  void setUseTokenMenu(bool value);
167 
168 protected Q_SLOTS:
169 
170  virtual void slotTokenTriggered(const QString&);
171 
172 private:
173 
174  QPushButton* createButton(const QString& name, const QIcon& icon);
175 
176 private:
177 
178  // Disable
179  Rule(QObject*) = delete;
180  Rule(const Rule&) = delete;
181  Rule& operator=(const Rule&) = delete;
182 
183 private:
184 
185  class Private;
186  Private* const d;
187 };
188 
190 
191 } // namespace Digikam
192 
193 #endif // DIGIKAM_RULE_H
Definition: parseresults.h:37
Definition: parsesettings.h:43
Definition: rule.h:42
bool addToken(const QString &id, const QString &description, const QString &actionName=QString())
Definition: rule.cpp:199
virtual void slotTokenTriggered(const QString &)
Definition: rule.cpp:236
void signalTokenTriggered(const QString &)
void setUseTokenMenu(bool value)
Definition: rule.cpp:221
TokenList & tokens() const
Definition: rule.cpp:231
QAction * registerMenu(QMenu *parent)
Definition: rule.cpp:167
QPixmap icon(Rule::IconType type=Rule::Action) const
Definition: rule.cpp:86
void setRegExp(const QRegularExpression &regExp)
Definition: rule.cpp:119
virtual QString parseOperation(ParseSettings &settings, const QRegularExpressionMatch &match)=0
QRegularExpression & regExp() const
Definition: rule.cpp:114
virtual void reset()
Definition: rule.cpp:246
Rule(const QString &name)
Definition: rule.cpp:58
static QString escapeToken(const QString &token)
Definition: rule.cpp:250
IconType
Definition: rule.h:48
@ Dialog
Definition: rule.h:50
@ Action
Definition: rule.h:49
bool isValid() const
Definition: rule.cpp:241
QPushButton * registerButton(QWidget *parent)
Definition: rule.cpp:136
~Rule() override
Definition: rule.cpp:73
void setIcon(const QString &pixmap)
Definition: rule.cpp:81
void setDescription(const QString &desc)
Definition: rule.cpp:104
ParseResults parse(ParseSettings &settings)
Definition: rule.cpp:267
bool useTokenMenu() const
Definition: rule.cpp:226
QString description() const
Definition: rule.cpp:109
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43
QList< Rule * > RulesList
Definition: rule.h:189