File indexing completed on 2025-03-09 03:57:05
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-08-08 0007 * Description : a token class 0008 * 0009 * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_TOKEN_H 0016 #define DIGIKAM_TOKEN_H 0017 0018 // Qt includes 0019 0020 #include <QList> 0021 #include <QObject> 0022 #include <QString> 0023 0024 class QAction; 0025 0026 namespace Digikam 0027 { 0028 0029 /** 0030 * @brief %Token is the smallest parsing unit in AdvancedRename utility 0031 * 0032 * The %Token class represents the smallest parsing unit for the Parser class. Every string you enter as a renaming pattern 0033 * is a combination of tokens and literal text. For example 0034 * @code 0035 * "[file]{upper}_###_abc.[ext]{lower}" 0036 * @endcode 0037 * is composed of five tokens 0038 * @code 0039 * [file] 0040 * {upper} 0041 * ### 0042 * .[ext] 0043 * {lower} 0044 * @endcode 0045 * and two literals 0046 * @code 0047 * _ 0048 * _abc 0049 * @endcode 0050 * A rule must assign at least one token object, to make parsing work. More than one token can be assigned to a %Rule. 0051 * @see Rule::addToken() 0052 * 0053 */ 0054 class Token : public QObject 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 0060 explicit Token(const QString& id, const QString& description); 0061 ~Token() override; 0062 0063 /** 0064 * @return The ID of the token. This is the actual token string, for example 0065 * @code 0066 * "[file]" 0067 * @endcode 0068 * This id will be emitted as a signal by slotTriggered(). 0069 */ 0070 QString id() 0071 { 0072 return m_id; 0073 }; 0074 0075 /** 0076 * @return The description of the token. It can be used for example in the tooltip of the AdvancedRenameWidget. 0077 */ 0078 QString description() 0079 { 0080 return m_description; 0081 }; 0082 0083 /** 0084 * @return The action of the token. This action can be connected to a button or menu item. If triggered, high-level classes 0085 * like AdvancedRenameWidget can connect to the signal and display the emitted text in the line edit input widget. 0086 */ 0087 QAction* action() 0088 { 0089 return m_action; 0090 }; 0091 0092 Q_SIGNALS: 0093 0094 /** 0095 * This signal is emitted when the action of the token is triggered. 0096 */ 0097 void signalTokenTriggered(const QString&); 0098 0099 private Q_SLOTS: 0100 0101 /** 0102 * This slot will emit signalTokenTriggered() when the action of the token is triggered. 0103 */ 0104 void slotTriggered(); 0105 0106 private: 0107 0108 // Disable 0109 Token(QObject*) = delete; 0110 Token(const Token&) = delete; 0111 Token& operator=(const Token&) = delete; 0112 0113 private: 0114 0115 QString m_id; 0116 QString m_description; 0117 QAction* m_action; 0118 }; 0119 0120 typedef QList<Token*> TokenList; 0121 0122 } // namespace Digikam 0123 0124 #endif // DIGIKAM_TOKEN_H