File indexing completed on 2024-05-19 16:08:55

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_VIEW_MODEL
0021 #define CALLIGRA_SHEETS_MAP_VIEW_MODEL
0022 
0023 #include "MapModel.h"
0024 
0025 class KoCanvasBase;
0026 class KoShape;
0027 
0028 class KXMLGUIClient;
0029 
0030 class QAction;
0031 
0032 namespace Calligra
0033 {
0034 namespace Sheets
0035 {
0036 
0037 /**
0038  * Extends the map model by active sheet tracking.
0039  *
0040  * KPART_TODO: fix the actions in a document with multiple sheets, we used to call
0041  *             d->xmlGuiClient->plugActionList("go_goto_sheet_actionlist", actions);
0042  *             in the eventFilter.
0043  */
0044 class MapViewModel : public MapModel
0045 {
0046     Q_OBJECT
0047 public:
0048     MapViewModel(Map *map, KoCanvasBase *canvas, KXMLGUIClient *xmlGuiClient);
0049     ~MapViewModel() override;
0050 
0051     // QAbstractItemModel interface
0052     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0053     Qt::ItemFlags flags(const QModelIndex &index) const override;
0054     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0055 
0056     Sheet* activeSheet() const;
0057 
0058 public Q_SLOTS:
0059     /**
0060      * Set the active \p sheet and emits activeSheetChanged(Sheet*) afterwards.
0061      */
0062     void setActiveSheet(Sheet* sheet);
0063 
0064 private Q_SLOTS:
0065     /**
0066      * Adds \p sheet to the goto sheet actions.
0067      */
0068     void addSheet(Sheet *sheet) override;
0069 
0070     /**
0071      * Removes \p sheet from the goto sheet actions.
0072      */
0073     void removeSheet(Sheet *sheet) override;
0074 
0075     /**
0076      * Adds the \p shape, if \p sheet is active.
0077      */
0078     void addShape(Sheet *sheet, KoShape *shape);
0079 
0080     /**
0081      * Removes the \p shape, if \p sheet is active.
0082      */
0083     void removeShape(Sheet *sheet, KoShape *shape);
0084 
0085     /**
0086      * Activates the associated sheet of the \p action.
0087      */
0088     void gotoSheetActionTriggered(QAction *action);
0089 
0090 Q_SIGNALS:
0091     void activeSheetChanged(Sheet* sheet);
0092 
0093 private:
0094     class Private;
0095     Private * const d;
0096 };
0097 
0098 } // namespace Sheets
0099 } // namespace Calligra
0100 
0101 #endif // CALLIGRA_SHEETS_MAP_VIEW_MODEL