File indexing completed on 2024-05-19 04:36:33

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2014-2016 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef TIKZUI_EDITOR_PRIVATE_H
0021 #define TIKZUI_EDITOR_PRIVATE_H
0022 
0023 #include <tikz/ui/Editor.h>
0024 #include <tikz/ui/Application.h>
0025 #include <tikz/ui/MainWindow.h>
0026 
0027 #include <QList>
0028 #include <QPointer>
0029 #include <QVector>
0030 
0031 namespace tikz {
0032 namespace ui {
0033 
0034 class DocumentPrivate;
0035 class ViewPrivate;
0036 
0037 /**
0038  * tikz::ui::EditorPrivate
0039  * One instance of this class is hold alive during
0040  * a kate part session, as long as any factory, document
0041  * or view stay around, here is the place to put things
0042  * which are needed and shared by all this objects ;)
0043  */
0044 class EditorPrivate : public tikz::ui::Editor
0045 {
0046     Q_OBJECT
0047 
0048     friend class tikz::ui::Editor;
0049 
0050 private:
0051     /**
0052      * Default constructor, private, as singleton
0053      * @param staticInstance pointer to fill with content of this
0054      */
0055     EditorPrivate(QPointer<tikz::ui::EditorPrivate> &staticInstance);
0056 
0057 public:
0058     /**
0059      * Destructor
0060      */
0061     ~EditorPrivate();
0062 
0063     /**
0064      * Create a new document object
0065      * @param parent parent object
0066      * @return created tikz::ui::Document
0067      */
0068     tikz::ui::Document *createDocument(QObject *parent) override;
0069 
0070     /**
0071      * Returns a list of all documents of this editor.
0072      * @return list of all existing documents
0073      */
0074     QVector<tikz::ui::Document *> documents() override;
0075 
0076     /**
0077      * Get a list of all Views of this editor.
0078      * \return list of all existing Views
0079      */
0080     QVector<tikz::ui::View *> views() override;
0081 
0082     /**
0083      * Set the global application object.
0084      * This will allow the editor component to access
0085      * the hosting application.
0086      * @param application application object
0087      */
0088     void setApplication(tikz::ui::Application *application) override
0089     {
0090         // switch back to dummy application?
0091         m_application = application ? application : &m_dummyApplication;
0092     }
0093 
0094     /**
0095      * Current hosting application, if any set.
0096      * @return current application object or nullptr
0097      */
0098     tikz::ui::Application *application() const override
0099     {
0100         return m_application;
0101     }
0102 
0103     /**
0104      * Configuration management
0105      */
0106 public:
0107     /**
0108      * Number of available config pages
0109      * If the editor returns a number < 1, it doesn't support this
0110      * and the embedding app should use the configDialog () instead
0111      * @return number of config pages
0112      */
0113     int configPages() const override;
0114 
0115     /**
0116      * Returns config page with the given number,
0117      * config pages from 0 to configPages()-1 are available
0118      * if configPages() > 0
0119      */
0120     tikz::ui::ConfigPage *configPage(int number, QWidget *parent) override;
0121 
0122     /**
0123      * TikZKit Internal stuff ;)
0124      */
0125 public:
0126     /**
0127      * singleton accessor
0128      * @return instance of the factory
0129      */
0130     static EditorPrivate *self();
0131 
0132     /**
0133      * register document at the factory
0134      * this allows us to loop over all docs for example on config changes
0135      * @param doc document to register
0136      */
0137     void registerDocument(tikz::ui::DocumentPrivate *doc);
0138 
0139     /**
0140      * unregister document at the factory
0141      * @param doc document to register
0142      */
0143     void unregisterDocument(tikz::ui::DocumentPrivate *doc);
0144 
0145     /**
0146      * return a list of all registered docs
0147      * @return all known documents
0148      */
0149     QVector<tikz::ui::DocumentPrivate *> tikzDocuments();
0150 
0151     /**
0152      * register view at the factory
0153      * this allows us to loop over all views for example on config changes
0154      * @param view view to register
0155      */
0156     void registerView(tikz::ui::ViewPrivate *view);
0157 
0158     /**
0159      * unregister view at the factory
0160      * @param view view to unregister
0161      */
0162     void unregisterView(tikz::ui::ViewPrivate *view);
0163 
0164     /**
0165      * Return a list of all registered tikz::ui::ViewPrivate%s
0166      */
0167     QVector<tikz::ui::ViewPrivate *> tikzViews();
0168 
0169 public:
0170     /**
0171      * Dummy main window to be null safe.
0172      * @return dummy main window
0173      */
0174     tikz::ui::MainWindow *dummyMainWindow()
0175     {
0176         return &m_dummyMainWindow;
0177     }
0178 
0179 private:
0180     /**
0181      * Dummy application object to be null safe
0182      */
0183     tikz::ui::Application m_dummyApplication;
0184 
0185     /**
0186      * Dummy main window to be null safe
0187      */
0188     tikz::ui::MainWindow m_dummyMainWindow;
0189 
0190     /**
0191      * registered docs, map from general to specialized pointer
0192      */
0193     QVector<tikz::ui::DocumentPrivate *> m_documents;
0194 
0195     /**
0196      * registered views
0197      */
0198     QVector<tikz::ui::ViewPrivate *> m_views;
0199 
0200     /**
0201      * access to application
0202      */
0203     QPointer<tikz::ui::Application> m_application;
0204 };
0205 
0206 }
0207 }
0208 
0209 #endif // TIKZUI_EDITOR_PRIVATE_H
0210 
0211 // kate: indent-width 4; replace-tabs on;