Warning, file /office/skrooge/skgbasegui/skgshow.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGSHOW_H
0007 #define SKGSHOW_H
0008 /** @file
0009  * A widget to select what to show.
0010  *
0011  * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 
0014 #include <qmap.h>
0015 #include <qtimer.h>
0016 #include <qtoolbutton.h>
0017 #include <qmenu.h>
0018 
0019 #include "skgbasegui_export.h"
0020 
0021 class QAction;
0022 class QActionGroup;
0023 
0024 class SKGBASEGUI_EXPORT SKGMenu : public QMenu
0025 {
0026 public:
0027     explicit SKGMenu(QWidget* parent = nullptr) : QMenu(parent)
0028     {
0029     }
0030 
0031 protected:
0032     bool focusNextPrevChild(bool next) override
0033     {
0034         return QWidget::focusNextPrevChild(next);
0035     }
0036 };
0037 
0038 /**
0039  * This file is a widget to select what to show
0040  */
0041 class SKGBASEGUI_EXPORT SKGShow : public QToolButton
0042 {
0043     Q_OBJECT
0044 
0045     /**
0046      * Mode
0047      */
0048     Q_PROPERTY(OperatorMode mode READ getMode WRITE setMode NOTIFY modified)
0049 
0050     /**
0051      * Display Title
0052      */
0053     Q_PROPERTY(bool displayTitle READ getDisplayTitle WRITE setDisplayTitle NOTIFY modified)
0054 public:
0055     /**
0056      * This enumerate defines type of operator
0057      */
0058     enum OperatorMode {AND,   /**< AND*/
0059                        OR      /**< OR*/
0060                       };
0061 
0062     /**
0063      * This enumerate defines type of operator
0064      */
0065     Q_ENUM(OperatorMode)
0066 
0067     /**
0068      * Default Constructor
0069      * @param iParent the parent
0070      */
0071     explicit SKGShow(QWidget* iParent);
0072 
0073     /**
0074      * Default Destructor
0075      */
0076     ~SKGShow() override;
0077 
0078     /**
0079      * Get the current state
0080      * @return a string containing all activated item identifiers (separated by ;)
0081      */
0082     virtual QString getState();
0083 
0084     /**
0085      * Set the current state
0086      * @param iState a string containing all activated item identifiers (separated by ;)
0087      */
0088     virtual void setState(const QString& iState);
0089 
0090     /**
0091      * Get the current mode
0092      * @return the mode
0093      */
0094     virtual OperatorMode getMode();
0095 
0096     /**
0097      * Set the current mode
0098      * @param iMode the mode
0099      */
0100     virtual void setMode(OperatorMode iMode);
0101 
0102     /**
0103      * Set the default state
0104      * @param iState a string containing all activated item identifiers (separated by ;)
0105      */
0106     virtual void setDefaultState(const QString& iState);
0107 
0108     /**
0109      * Get the current display mode
0110      * @return true of false
0111      */
0112     virtual bool getDisplayTitle();
0113 
0114     /**
0115      * Set the current display mode
0116      * @param iDisplay true if you want to see the selected filter of false
0117      */
0118     virtual void setDisplayTitle(bool iDisplay);
0119 
0120     /**
0121      * Get the current where clause
0122      * @return a where clause string
0123      */
0124     virtual QString getWhereClause() const;
0125 
0126     /**
0127      * Remove all items
0128      */
0129     virtual void clear();
0130 
0131     /**
0132      * @brief Get the number of items
0133      *
0134      * @return the number of items
0135      **/
0136     virtual int count();
0137 
0138     /**
0139      * @brief Get the action for an identifier
0140      *
0141      * @param iIdentifier unique identifier of the item
0142      * @return the action
0143      **/
0144     virtual QAction* getAction(const QString& iIdentifier) const;
0145 
0146     /**
0147      * @brief Add an item to the menu
0148      *
0149      * @param iIdentifier unique identifier of the item
0150      * @param iText text
0151      * @param iIcon icon Defaults to "".
0152      * @param iWhereClose the where clause Defaults to "".
0153      * @param iListIdToCheckWhenChecked list of item identifiers (separated by ;) to check when checked Defaults to "".
0154      * @param iListIdToUncheckWhenChecked list of item identifiers (separated by ;) to uncheck when unchecked Defaults to "".
0155      * @param iListIdToCheckWhenUnchecked list of item identifiers (separated by ;) to check when checked Defaults to "".
0156      * @param iListIdToUncheckWhenUnchecked list of item identifiers (separated by ;) to uncheck when unchecked Defaults to "".
0157      * @param iShortcut the associated shortcut.
0158      * @return the index of the new item
0159      **/
0160     virtual int addItem(const QString& iIdentifier, const QString& iText, const QString& iIcon = QString(),
0161                         const QString& iWhereClose = QString(),
0162                         const QString& iListIdToCheckWhenChecked = QString(),
0163                         const QString& iListIdToUncheckWhenChecked = QString(),
0164                         const QString& iListIdToCheckWhenUnchecked = QString(),
0165                         const QString& iListIdToUncheckWhenUnchecked = QString(),
0166                         const QKeySequence& iShortcut = QKeySequence());
0167 
0168     /**
0169      * @brief Add a period item to the menu
0170      *
0171      * @param iIdentifier unique identifier of the item
0172      * @return the index of the new item
0173      **/
0174     virtual int addPeriodItem(const QString& iIdentifier);
0175 
0176     /**
0177      * @brief Add an item to the menu
0178      *
0179      * @param iIdentifier unique identifier of the item
0180      * @param iText text
0181      * @param iIcon icon Defaults to "".
0182      * @param iWhereClose icon Defaults to "".
0183      * @param iGroup the group of actions.
0184      * @param iShortcut the associated shortcut.
0185      * @return the index of the new item
0186      **/
0187     virtual int addGroupedItem(const QString& iIdentifier,
0188                                const QString& iText,
0189                                const QString& iIcon = QString(),
0190                                const QString& iWhereClose = QString(),
0191                                const QString& iGroup = QString(),
0192                                const QKeySequence& iShortcut = QKeySequence());
0193 
0194     /**
0195      * @brief Set the list of items to check when iIndex is checked
0196      *
0197      * @param iIndex index of the item (@see addItem)
0198      * @param iIds list of item identifiers (separated by ;)
0199      **/
0200     virtual void setListIdToCheckWhenChecked(int iIndex, const QString& iIds);
0201 
0202     /**
0203      * @brief Set the list of items to uncheck when iIndex is checked
0204      *
0205      * @param iIndex index of the item (@see addItem)
0206      * @param iIds list of item identifiers (separated by ;)
0207      **/
0208     virtual void setListIdToUncheckWhenChecked(int iIndex, const QString& iIds);
0209 
0210     /**
0211      * @brief Set the list of items to check when iIndex is unchecked
0212      *
0213      * @param iIndex index of the item (@see addItem)
0214      * @param iIds list of item identifiers (separated by ;)
0215      **/
0216     virtual void setListIdToCheckWhenUnchecked(int iIndex, const QString& iIds);
0217 
0218     /**
0219      * @brief Set the list of items to uncheck when iIndex is unchecked
0220      *
0221      * @param iIndex index of the item (@see addItem)
0222      * @param iIds list of item identifiers (separated by ;)
0223      **/
0224     virtual void setListIdToUncheckWhenUnchecked(int iIndex, const QString& iIds);
0225 
0226     /**
0227      * @brief Add a separator
0228      *
0229      * @return void
0230      **/
0231     virtual void addSeparator();
0232 
0233 Q_SIGNALS:
0234     /**
0235      * @brief Emitted when an item is changed
0236      *
0237      * @return void
0238      **/
0239     void stateChanged();
0240 
0241     /**
0242      * This signal is launched when the error is modified
0243      */
0244     void modified();
0245 
0246 private Q_SLOTS:
0247     /**
0248      * @brief trigger
0249      **/
0250     void trigger();
0251 
0252     /**
0253      * @brief trigger
0254      **/
0255     void triggerRefreshOnly();
0256 
0257 private:
0258     Q_DISABLE_COPY(SKGShow)
0259 
0260     QString getTitle() const;
0261     void refreshTitle();
0262 
0263     SKGMenu* m_menu;
0264     QTimer m_timer;
0265     QString m_defaultState;
0266     OperatorMode m_mode;
0267     bool m_inTrigger;
0268     bool m_displayTitle;
0269 
0270     QList<QAction*> m_actions;
0271     QStringList m_icons;
0272     QMap<QAction*, QString> m_check_to_check;
0273     QMap<QAction*, QString> m_uncheck_to_check;
0274     QMap<QAction*, QString> m_check_to_uncheck;
0275     QMap<QAction*, QString> m_uncheck_to_uncheck;
0276     QMap<QAction*, QString> m_whereclause;
0277     QMap<QString, QActionGroup*> m_groups;
0278 };
0279 
0280 #endif  // SKGSHOW_H