File indexing completed on 2024-05-12 03:47:20

0001 /*
0002     File                 : CantorWorksheet.h
0003     Project              : LabPlot
0004     Description          : Aspect providing a Cantor Worksheets for Multiple backends
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2015 Garvit Khatri <garvitdelhi@gmail.com>
0007     SPDX-FileCopyrightText: 2016-2023 Alexander Semke <alexander.semke@web.de>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef CANTORWORKSHEET_H
0012 #define CANTORWORKSHEET_H
0013 
0014 #include <backend/core/AbstractPart.h>
0015 #ifdef HAVE_CANTOR_LIBS
0016 #include <cantor/session.h>
0017 #endif
0018 
0019 namespace Cantor {
0020 class PanelPlugin;
0021 class WorksheetAccessInterface;
0022 }
0023 
0024 namespace KParts {
0025 class ReadWritePart;
0026 }
0027 
0028 class QAbstractItemModel;
0029 class CantorWorksheetView;
0030 class Column;
0031 
0032 class CantorWorksheet : public AbstractPart {
0033     Q_OBJECT
0034 
0035 public:
0036     explicit CantorWorksheet(const QString& name, bool loading = false);
0037 
0038     bool init(QByteArray* content = nullptr);
0039     const QString& error() const;
0040 
0041     QWidget* view() const override;
0042     QMenu* createContextMenu() override;
0043     void fillColumnContextMenu(QMenu*, Column*);
0044     QIcon icon() const override;
0045 
0046     bool exportView() const override;
0047     bool printView() override;
0048     bool printPreview() const override;
0049 
0050     void evaluate();
0051     void restart();
0052 
0053     void save(QXmlStreamWriter*) const override;
0054     bool load(XmlStreamReader*, bool preview) override;
0055 
0056     QString backendName();
0057     KParts::ReadWritePart* part();
0058     QList<Cantor::PanelPlugin*> getPlugins();
0059 
0060 private:
0061     mutable CantorWorksheetView* m_view{nullptr};
0062     QString m_backendName;
0063     QString m_error;
0064 #ifdef HAVE_CANTOR_LIBS
0065     Cantor::Session* m_session{nullptr};
0066 #endif
0067     KParts::ReadWritePart* m_part{nullptr};
0068     QList<Cantor::PanelPlugin*> m_plugins;
0069     bool m_pluginsLoaded{false};
0070     QAbstractItemModel* m_variableModel{nullptr};
0071     Cantor::WorksheetAccessInterface* m_worksheetAccess{nullptr};
0072 
0073     void parseData(int row);
0074 
0075 private Q_SLOTS:
0076     void dataChanged(const QModelIndex&);
0077     void rowsInserted(const QModelIndex& parent, int first, int last);
0078     void rowsAboutToBeRemoved(const QModelIndex& parent, int first, int last);
0079     void modelReset();
0080     void modified();
0081 
0082 Q_SIGNALS:
0083     void requestProjectContextMenu(QMenu*);
0084 #ifdef HAVE_CANTOR_LIBS
0085     void statusChanged(Cantor::Session::Status);
0086 #endif
0087 };
0088 
0089 #endif // CANTORWORKSHEET_H