File indexing completed on 2024-04-28 16:21:24

0001 /* This file is part of the KDE project
0002    Copyright 2009 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef CALLIGRA_SHEETS_MAP_MODEL
0021 #define CALLIGRA_SHEETS_MAP_MODEL
0022 
0023 #include <QAbstractListModel>
0024 
0025 class KUndo2Command;
0026 
0027 namespace Calligra
0028 {
0029 namespace Sheets
0030 {
0031 class Map;
0032 class Sheet;
0033 
0034 /**
0035  * A model for the 'embedded document'.
0036  * Actually, a model for a sheet list.
0037  * \ingroup Model
0038  */
0039 class MapModel : public QAbstractListModel
0040 {
0041     Q_OBJECT
0042 public:
0043     explicit MapModel(Map *map);
0044     ~MapModel() override;
0045 
0046     // QAbstractItemModel interface
0047     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0048     Qt::ItemFlags flags(const QModelIndex &index) const override;
0049     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0050     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0051     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0052     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0053 
0054 public Q_SLOTS:
0055     /**
0056      * Hides \p sheet, if \p hidden is \c true and \p sheet is visible.
0057      * Shows \p sheet, if \p hidden is \c false and \p sheet is hidden.
0058      * \return \c true on success; \c false on failure
0059      */
0060     bool setHidden(Sheet* sheet, bool hidden = true);
0061 
0062 Q_SIGNALS:
0063     void addCommandRequested(KUndo2Command* command);
0064 
0065 protected:
0066     Map* map() const;
0067 
0068 protected Q_SLOTS:
0069     virtual void addSheet(Sheet *sheet);
0070     virtual void removeSheet(Sheet *sheet);
0071 
0072 private:
0073     class Private;
0074     Private * const d;
0075 };
0076 
0077 } // namespace Sheets
0078 } // namespace Calligra
0079 
0080 #endif // CALLIGRA_SHEETS_MAP_MODEL