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 #include "EditorPrivate.h" 0020 #include "DocumentPrivate.h" 0021 #include "ViewPrivate.h" 0022 0023 #include <tikz/core/tikz.h> 0024 #include <tikz/core/Value.h> 0025 #include <tikz/core/Pos.h> 0026 #include <tikz/core/Style.h> 0027 0028 #include <QApplication> 0029 0030 namespace tikz { 0031 namespace ui { 0032 0033 EditorPrivate::EditorPrivate(QPointer<tikz::ui::EditorPrivate> &staticInstance) 0034 : tikz::ui::Editor(this) 0035 , m_dummyApplication(nullptr) 0036 , m_dummyMainWindow(nullptr) 0037 , m_application(&m_dummyApplication) 0038 { 0039 // remember this 0040 staticInstance = this; 0041 0042 // 0043 // register some datatypes 0044 // 0045 qRegisterMetaType<tikz::Arrow>("Arrow"); 0046 qRegisterMetaType<tikz::LineCap>("LineCap"); 0047 qRegisterMetaType<tikz::LineJoin>("LineJoin"); 0048 qRegisterMetaType<tikz::PenStyle>("PenStyle"); 0049 qRegisterMetaType<tikz::Shape>("Shape"); 0050 qRegisterMetaType<tikz::TextAlignment>("TextAlignment"); 0051 qRegisterMetaType<tikz::Unit>("Unit"); 0052 qRegisterMetaType<tikz::Pos>("Pos"); 0053 qRegisterMetaType<tikz::Value>("Value"); 0054 qRegisterMetaType<tikz::core::Style*>("Style*"); 0055 qRegisterMetaType<tikz::core::Uid>("Uid"); 0056 } 0057 0058 EditorPrivate::~EditorPrivate() 0059 { 0060 } 0061 0062 tikz::ui::Document * EditorPrivate::createDocument(QObject *parent) 0063 { 0064 Q_UNUSED(parent) // FIXME: delete parameter? or is 'this' below wrong? 0065 auto doc = new tikz::ui::DocumentPrivate(this); 0066 0067 Q_EMIT documentCreated(doc); 0068 0069 return doc; 0070 } 0071 0072 int EditorPrivate::configPages() const 0073 { 0074 return 0; 0075 } 0076 0077 tikz::ui::ConfigPage * EditorPrivate::configPage(int number, QWidget *parent) 0078 { 0079 Q_UNUSED(number) 0080 Q_UNUSED(parent) 0081 0082 return nullptr; 0083 } 0084 0085 /** 0086 * Cleanup the tikz::ui::EditorPrivate during QCoreApplication shutdown 0087 */ 0088 static void cleanupGlobal() 0089 { 0090 /** 0091 * delete if there 0092 */ 0093 delete EditorPrivate::self(); 0094 } 0095 0096 EditorPrivate * EditorPrivate::self() 0097 { 0098 /** 0099 * remember the static instance in a QPointer 0100 */ 0101 static bool inited = false; 0102 static QPointer<tikz::ui::EditorPrivate> staticInstance; 0103 0104 /** 0105 * just return it, if already inited 0106 */ 0107 if (inited) { 0108 return staticInstance.data(); 0109 } 0110 0111 /** 0112 * start init process 0113 */ 0114 inited = true; 0115 0116 /** 0117 * now create the object and store it 0118 */ 0119 new tikz::ui::EditorPrivate(staticInstance); 0120 0121 /** 0122 * register cleanup 0123 * let use be deleted during QCoreApplication shutdown 0124 */ 0125 qAddPostRoutine(cleanupGlobal); 0126 0127 /** 0128 * return instance 0129 */ 0130 return staticInstance.data(); 0131 } 0132 0133 void EditorPrivate::registerDocument(tikz::ui::DocumentPrivate *doc) 0134 { 0135 Q_ASSERT (!m_documents.contains(doc)); 0136 m_documents.append(doc); 0137 } 0138 0139 void EditorPrivate::unregisterDocument(tikz::ui::DocumentPrivate *doc) 0140 { 0141 Q_ASSERT (m_documents.contains(doc)); 0142 m_documents.remove(m_documents.indexOf(doc)); 0143 } 0144 0145 QVector<tikz::ui::Document *> EditorPrivate::documents() 0146 { 0147 QVector<tikz::ui::Document*> docs; 0148 docs.reserve(m_documents.size()); 0149 for (int i = 0; i < m_documents.size(); ++i) { 0150 docs.append(m_documents.at(i)); 0151 } 0152 return docs; 0153 } 0154 0155 QVector<tikz::ui::View *> EditorPrivate::views() 0156 { 0157 QVector<tikz::ui::View*> list; 0158 list.reserve(m_views.size()); 0159 for (int i = 0; i < m_views.size(); ++i) { 0160 list.append(m_views.at(i)); 0161 } 0162 return list; 0163 } 0164 0165 QVector<tikz::ui::DocumentPrivate *> EditorPrivate::tikzDocuments() 0166 { 0167 return m_documents; 0168 } 0169 0170 void EditorPrivate::registerView(tikz::ui::ViewPrivate *view) 0171 { 0172 Q_ASSERT (!m_views.contains(view)); 0173 m_views.append(view); 0174 } 0175 0176 void EditorPrivate::unregisterView(tikz::ui::ViewPrivate *view) 0177 { 0178 Q_ASSERT (m_views.contains(view)); 0179 m_views.remove(m_views.indexOf(view)); 0180 } 0181 0182 QVector<tikz::ui::ViewPrivate *> EditorPrivate::tikzViews() 0183 { 0184 return m_views; 0185 } 0186 0187 } 0188 } 0189 0190 // kate: indent-width 4; replace-tabs on;