File indexing completed on 2024-05-12 16:01:26

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Cyrille Berger <cberger@cberger.net>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef _KIS_BOOKMARKED_CONFIGURATIONS_MODEL_H_
0008 #define _KIS_BOOKMARKED_CONFIGURATIONS_MODEL_H_
0009 
0010 #include <QAbstractListModel>
0011 
0012 #include <kritaui_export.h>
0013 
0014 class KLocalizedString;
0015 
0016 class KisBookmarkedConfigurationManager;
0017 #include <kis_serializable_configuration.h>
0018 
0019 /**
0020  * This class provides the basic functionality for a model of a bookmark
0021  * of configurations.
0022  */
0023 class KRITAUI_EXPORT KisBookmarkedConfigurationsModel : public QAbstractListModel
0024 {
0025 public:
0026     /**
0027      * Initialized thee model with the bookmarks manager
0028      */
0029     KisBookmarkedConfigurationsModel(KisBookmarkedConfigurationManager*);
0030     ~KisBookmarkedConfigurationsModel() override;
0031     /**
0032      * @return  the bookmarked configuration manager associated with this model.
0033      */
0034     KisBookmarkedConfigurationManager* bookmarkedConfigurationManager();
0035     /**
0036      * @return the number of configurations (the minimum is always 2, the default
0037      * configuration and the last used configuration are always present)
0038      */
0039     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0040     /**
0041      * When role == Qt::DisplayRole, this function will return the name of the
0042      * configuration.
0043      */
0044     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0045     bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole) override;
0046     /**
0047      * @return the configuration at the given index
0048      */
0049     KisSerializableConfigurationSP configuration(const QModelIndex &index) const;
0050     /**
0051      * @return the index corresponding to the @p name .
0052      */
0053     QModelIndex indexFor(const QString& name) const;
0054     /**
0055      * @return true if the configuration at the given index can be removed
0056      */
0057     virtual bool isIndexDeletable(const QModelIndex &index) const;
0058     /**
0059      * @return the flags associated to the index
0060      */
0061     Qt::ItemFlags flags(const QModelIndex & index) const override;
0062     /**
0063      * Insert a new configuration.
0064      */
0065     virtual void newConfiguration(KLocalizedString baseName, const KisSerializableConfigurationSP config);
0066     /**
0067      * Save a configuration to the bookmark manager.
0068      */
0069     virtual void saveConfiguration(const QString & name, const KisSerializableConfigurationSP config);
0070     /**
0071      * Delete the configuration at the given index. (if possible)
0072      */
0073     virtual void deleteIndex(const QModelIndex &index);
0074 private:
0075     struct Private;
0076     Private* const d;
0077 };
0078 
0079 #endif