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

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2014-2016 Dominik Haumann <dhaumann@kde.org>
0004  * Copyright (C) 2014 Christoph Cullmann <cullmann@kde.org>
0005  *
0006  * This library is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU Library General Public License as published
0008  * by the Free Software Foundation, either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, see
0018  * <http://www.gnu.org/licenses/>.
0019  */
0020 
0021 #ifndef TIKZUI_APPLICATION_H
0022 #define TIKZUI_APPLICATION_H
0023 
0024 #include "tikzui_export.h"
0025 #include <QObject>
0026 #include <QVector>
0027 
0028 namespace tikz {
0029 namespace ui {
0030 
0031 // class Plugin;
0032 class Document;
0033 class MainWindow;
0034 
0035 /**
0036  * This class allows the application that embedds the tikz::ui component to
0037  * allow it access to application wide information and interactions.
0038  *
0039  * For example the component can get the current active main window of the application.
0040  *
0041  * The application must pass a pointer to the Application object to the setApplication method of the
0042  * global editor instance and ensure that this object stays valid for the complete lifetime of the editor.
0043  *
0044  * It must not reimplement this class but construct an instance and pass a pointer to a QObject that
0045  * has the required slots to receive the requests.
0046  *
0047  * tikz::ui::Editor::instance()->application() will always return a non-nullptr object
0048  * to avoid the need for nullptr checks before calling the API.
0049  *
0050  * The same holds for activeMainWindow(), even if no main window is around, you will get a non-nullptr
0051  * interface object that allows to call the functions of the MainWindow without needs for a nullptr
0052  * check around it in the client code.
0053  */
0054 class TIKZKITUI_EXPORT Application : public QObject
0055 {
0056     Q_OBJECT
0057 
0058 public:
0059     /**
0060      * Construct an Application wrapper object.
0061      * The passed parent is both the parent of this QObject and the receiver of all interface
0062      * calls via invokeMethod.
0063      * @param parent object the calls are relayed to
0064      */
0065     Application(QObject *parent);
0066 
0067     /**
0068      * Virtual Destructor
0069      */
0070     virtual ~Application();
0071 
0072 //
0073 // MainWindow related accessors
0074 //
0075 public:
0076     /**
0077      * Get a list of all main windows.
0078      * @return all main windows, may be an empty list
0079      */
0080     QList<tikz::ui::MainWindow *> mainWindows();
0081 
0082     /**
0083      * Accessor to the active main window.
0084      * \return a pointer to the active mainwindow.
0085      *         Even if no main window is active a non-nullptr dummy interface
0086      *         is returned that allows to call interface functions without the
0087      *         need for null pointer checks.
0088      */
0089     tikz::ui::MainWindow *activeMainWindow();
0090 
0091 //
0092 // Document related accessors
0093 //
0094 public:
0095     /**
0096      * Get a list of all documents that are managed by the application.
0097      * This might contain less documents than the editor has in his documents () list.
0098      * @return all documents the application manages, may be an empty list.
0099      */
0100     QVector<tikz::ui::Document *> documents();
0101 
0102     /**
0103      * Get the document with the URL \p url.
0104      * if multiple documents match the searched url, return the first found one...
0105      * \param url the document's URL
0106      * \return the document with the given \p url or nullptr, if none found
0107      */
0108     tikz::ui::Document *findUrl(const QUrl &url);
0109 
0110     /**
0111      * Open the document \p url.
0112      * if the url is empty, a new empty document will be created
0113      * \param url the document's url
0114      * \return a pointer to the created document
0115      */
0116     tikz::ui::Document * openUrl(const QUrl &url);
0117 
0118     /**
0119      * Close the given \p document. If the document is modified, user will be asked if he wants that.
0120      * \param document the document to be closed
0121      * \return \e true on success, otherwise \e false
0122      */
0123     bool closeDocument(tikz::ui::Document *document);
0124 
0125 Q_SIGNALS:
0126     /**
0127      * This signal is emitted when the \p document was created.
0128      *
0129      * @param document document that was created
0130      */
0131     void documentCreated(tikz::ui::Document *document);
0132 
0133     /**
0134      * This signal is emitted before a \p document which should be closed is deleted
0135      * The document is still accessible and usable, but it will be deleted
0136      * after this signal was send.
0137      *
0138      * @param document document that will be deleted
0139      */
0140     void aboutToDeleteDocument(tikz::ui::Document *document);
0141 
0142     /**
0143      * This signal is emitted when the \p document has been deleted.
0144      *
0145      * Warning !!! DO NOT ACCESS THE DATA REFERENCED BY THE POINTER, IT IS ALREADY INVALID
0146      * Use the pointer only to remove mappings in hash or maps
0147      *
0148      * @param document document that is deleted
0149      */
0150     void documentDeleted(tikz::ui::Document *document);
0151 
0152 
0153 #if 0
0154 //
0155 // Application plugin accessors
0156 //
0157 public:
0158     /**
0159      * Get a plugin for the plugin with with identifier \p name.
0160      * \param name the plugin's name
0161      * \return pointer to the plugin if a plugin with \p name is loaded, otherwise nullptr
0162      */
0163     tikz::ui::Plugin *plugin(const QString &name);
0164 
0165     //
0166     // Signals related to application plugins
0167     //
0168 Q_SIGNALS:
0169     /**
0170      * This signal is emitted when an Plugin was loaded.
0171      *
0172      * @param name name of plugin
0173      * @param plugin the new plugin
0174      */
0175     void pluginCreated(const QString &name, tikz::ui::Plugin *plugin);
0176 
0177     /**
0178      * This signal is emitted when an Plugin got deleted.
0179      *
0180      * @param name name of plugin
0181      * @param plugin the deleted plugin
0182      *
0183      * Warning !!! DO NOT ACCESS THE DATA REFERENCED BY THE POINTER, IT IS ALREADY INVALID
0184      * Use the pointer only to remove mappings in hash or maps
0185      */
0186     void pluginDeleted(const QString &name, tikz::ui::Plugin *plugin);
0187 #endif
0188 
0189 private:
0190     /**
0191      * Private d-pointer class is our best friend ;)
0192      */
0193     friend class ApplicationPrivate;
0194 
0195     /**
0196      * Private d-pointer
0197      */
0198     class ApplicationPrivate *const d;
0199 };
0200 
0201 }
0202 }
0203 
0204 #endif // TIKZUI_APPLICATION_H
0205 
0206 // kate: indent-width 4; replace-tabs on;