File indexing completed on 2024-07-14 15:41:19

0001 /*
0002    SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #ifndef KHOTKEYSMODEL_H
0007 #define KHOTKEYSMODEL_H
0008 
0009 #include "libkhotkeysfwd.h"
0010 #include "settings.h"
0011 
0012 #include <QAbstractItemModel>
0013 
0014 /**
0015  */
0016 class KHotkeysModel : public QAbstractItemModel
0017 {
0018     Q_OBJECT
0019 
0020 public:
0021     enum ItemType {
0022         Other //!< Some unknown action type
0023         ,
0024         ActionDataGroup //!< A shortcut group
0025         ,
0026         SimpleActionData
0027     };
0028 
0029     enum Column {
0030         NameColumn,
0031         EnabledColumn,
0032         IsGroupColumn,
0033         TypeColumn,
0034     };
0035 
0036     /**
0037      * Default constructor
0038      *
0039      * @param
0040      */
0041     KHotkeysModel(QObject *parent = nullptr);
0042 
0043     /**
0044      * Destructor
0045      */
0046     ~KHotkeysModel() override;
0047 
0048     /**
0049      * \group Qt Model/View Framework methods
0050      */
0051     //@{
0052     QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const override;
0053     QModelIndex parent(const QModelIndex &index) const override;
0054     int rowCount(const QModelIndex &index) const override;
0055     int columnCount(const QModelIndex &index) const override;
0056     QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const override;
0057     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0058     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0059     Qt::ItemFlags flags(const QModelIndex &index) const override;
0060     //@}
0061 
0062     /**
0063      * \group Drag and Drop Support
0064      */
0065     //@{
0066     bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
0067     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0068     QStringList mimeTypes() const override;
0069     //@}
0070 
0071     /**
0072      * Add a group as child of @a parent.
0073      *
0074      * @return the index for the new group
0075      */
0076     QModelIndex addGroup(const QModelIndex &parent);
0077 
0078     /**
0079      * Export the input actions into @a config.
0080      */
0081     void exportInputActions(const QModelIndex &index, KConfigBase &config, const QString &id, const KHotKeys::ActionState state, bool allowMerging);
0082 
0083     /**
0084      *Import the input actions from @a config.
0085      */
0086     void importInputActions(const QModelIndex &index, KConfigBase const &config);
0087 
0088     /**
0089      * Get the KHotKeys::ActionDataBase behind the index.
0090      */
0091     KHotKeys::ActionDataBase *indexToActionDataBase(const QModelIndex &index) const;
0092 
0093     /**
0094      * Get the KHotKeys::ActionDataBase behind the index or 0.
0095      *
0096      * Getting 0 doesn't mean the index is invalid. It means you provided a
0097      * action object.
0098      */
0099     KHotKeys::ActionDataGroup *indexToActionDataGroup(const QModelIndex &index) const;
0100 
0101     /**
0102      * Insert @a data as a child of @a parent.
0103      */
0104     QModelIndex insertActionData(KHotKeys::ActionDataBase *data, const QModelIndex &parent);
0105 
0106     /**
0107      * Load the settings from the file
0108      */
0109     void load();
0110 
0111     /**
0112      * Move @p element to @p newGroup at @position.
0113      *
0114      * @param element  move this element
0115      * @param newGroup to this group
0116      * @param position and put it at this position. default is last
0117      *
0118      * @return @c true if moved, @c false if not.
0119      */
0120     bool moveElement(KHotKeys::ActionDataBase *element, KHotKeys::ActionDataGroup *newGroup, int position = -1);
0121 
0122     /**
0123      * Remove @a count rows starting with @a row under @a parent.
0124      */
0125     bool removeRows(int row, int count, const QModelIndex &parent) override;
0126 
0127     /**
0128      * Save the settings to the file
0129      */
0130     void save();
0131 
0132     /**
0133      * Return the settings we handle
0134      */
0135     KHotKeys::Settings *settings();
0136 
0137     void emitChanged(KHotKeys::ActionDataBase *item);
0138 
0139 private:
0140     KHotKeys::Settings _settings;
0141     KHotKeys::ActionDataGroup *_actions;
0142 };
0143 
0144 #endif /* #ifndef KHOTKEYSMODEL_HPP */