diff --git a/CMakeLists.txt b/CMakeLists.txt index dc4e623c..0ee8b28d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,95 +1,101 @@ ## # This file is part of Rocs. # Copyright 2008-2011 Tomaz Canabrava # Copyright 2010 Wagner Reck # Copyright 2011-2014 Andreas Cord-Landwehr # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ## project(rocs) cmake_minimum_required(VERSION 3.3) # KDE Application Version, managed by release script set(KDE_APPLICATIONS_VERSION_MAJOR "19") set(KDE_APPLICATIONS_VERSION_MINOR "11") set(KDE_APPLICATIONS_VERSION_MICRO "70") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") find_package(ECM 5.15.0 REQUIRED NO_MODULE) find_package(KF5DocTools) find_package(Boost "1.49" REQUIRED) find_package(Grantlee5 "5.0.0" REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include(ECMAddAppIcon) include(ECMAddTests) include(ECMInstallIcons) include(ECMOptionalAddSubdirectory) include(ECMSetupVersion) include(KDEInstallDirs) include(KDECompilerSettings NO_POLICY_SCOPE) include(KDECMakeSettings) include(FeatureSummary) include(GenerateExportHeader) find_package(Qt5 5.4 REQUIRED NO_MODULE COMPONENTS Core Gui QuickWidgets Script WebKit WebKitWidgets Widgets ScriptTools Svg Test XmlPatterns ) find_package(KF5 5.15 REQUIRED COMPONENTS Archive Config CoreAddons Crash Declarative I18n ItemViews TextEditor XmlGui ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${Boost_INCLUDE_DIRS} ) add_definitions(-DQT_NO_CAST_TO_ASCII) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) remove_definitions(-DQT_NO_CAST_FROM_ASCII) remove_definitions(-DQT_NO_CAST_FROM_BYTEARRAY) remove_definitions(-DQT_NO_KEYWORDS) +if(KF5Declarative_VERSION VERSION_GREATER_EQUAL "5.45") + add_definitions(-DKDECLARATIVE_HAVE_SETCONTEXT=1) +else() + add_definitions(-DKDECLARATIVE_HAVE_SETCONTEXT=0) +endif() + ecm_optional_add_subdirectory(libgraphtheory) ecm_optional_add_subdirectory(src) ecm_optional_add_subdirectory(icons) if(KF5DocTools_FOUND) ecm_optional_add_subdirectory(doc) endif() set_package_properties(Boost PROPERTIES DESCRIPTION "Boost C++ Libraries" URL "http://www.boost.org") feature_summary(WHAT ALL) install(FILES org.kde.rocs.appdata.xml DESTINATION ${CMAKE_INSTALL_METAINFODIR}) diff --git a/libgraphtheory/view.cpp b/libgraphtheory/view.cpp index 9201cf5c..bf0d762b 100644 --- a/libgraphtheory/view.cpp +++ b/libgraphtheory/view.cpp @@ -1,209 +1,214 @@ /* * Copyright 2014-2015 Andreas Cord-Landwehr * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "view.h" #include "edgetype.h" #include "nodetype.h" #include "edge.h" #include "models/nodemodel.h" #include "models/edgemodel.h" #include "models/nodepropertymodel.h" #include "models/edgepropertymodel.h" #include "models/nodetypemodel.h" #include "models/edgetypemodel.h" #include "qtquickitems/nodeitem.h" #include "qtquickitems/edgeitem.h" #include "dialogs/nodeproperties.h" #include "dialogs/edgeproperties.h" #include "logging_p.h" #include #include #include #include #include #include #include #include using namespace GraphTheory; class GraphTheory::ViewPrivate { public: ViewPrivate() : m_edgeModel(new EdgeModel()) , m_nodeModel(new NodeModel()) , m_edgeTypeModel(new EdgeTypeModel()) , m_nodeTypeModel(new NodeTypeModel) { } ~ViewPrivate() { delete m_edgeModel; delete m_nodeModel; delete m_edgeTypeModel; delete m_nodeTypeModel; } GraphDocumentPtr m_document; EdgeModel *m_edgeModel; NodeModel *m_nodeModel; EdgeTypeModel *m_edgeTypeModel; NodeTypeModel *m_nodeTypeModel; }; View::View(QWidget *parent) : QQuickWidget(parent) , d(new ViewPrivate) { setResizeMode(QQuickWidget::SizeRootObjectToView); // workaround for QTBUG-40765 qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); // prepare QML engine to be globally used KDeclarative::KDeclarative kdeclarative; kdeclarative.setTranslationDomain("libgraphtheory"); kdeclarative.setDeclarativeEngine(engine()); +#if KDECLARATIVE_HAVE_SETCONTEXT + kdeclarative.setupContext(); + KDeclarative::KDeclarative::setupEngine(engine()); +#else kdeclarative.setupBindings(); +#endif qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "Node"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "Edge"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "NodeType"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "EdgeType"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "NodeItem"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "EdgeItem"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "NodeModel"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "EdgeModel"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "NodePropertyModel"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "EdgePropertyModel"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "NodeTypeModel"); qmlRegisterType("org.kde.rocs.graphtheory", 1, 0, "EdgeTypeModel"); QUrl path = QUrl("qrc:/libgraphtheory/qml/Scene.qml"); QQmlComponent *component = new QQmlComponent(engine()); component->loadUrl(path); if (!component->isReady() ) { qCWarning(GRAPHTHEORY_GENERAL) << component->errorString(); return; } // register editor elements at context engine()->rootContext()->setContextProperty("nodeModel", d->m_nodeModel); engine()->rootContext()->setContextProperty("edgeModel", d->m_edgeModel); engine()->rootContext()->setContextProperty("nodeTypeModel", d->m_nodeTypeModel); engine()->rootContext()->setContextProperty("edgeTypeModel", d->m_edgeTypeModel); // create rootObject after context is set up QObject *topLevel = component->create(); // connections to QML signals connect(topLevel, SIGNAL(createNode(qreal,qreal,int)), this, SLOT(createNode(qreal,qreal,int))); connect(topLevel, SIGNAL(createEdge(GraphTheory::Node*,GraphTheory::Node*,int)), this, SLOT(createEdge(GraphTheory::Node*,GraphTheory::Node*,int))); connect(topLevel, SIGNAL(deleteNode(GraphTheory::Node*)), this, SLOT(deleteNode(GraphTheory::Node*))); connect(topLevel, SIGNAL(deleteEdge(GraphTheory::Edge*)), this, SLOT(deleteEdge(GraphTheory::Edge*))); connect(topLevel, SIGNAL(showNodePropertiesDialog(GraphTheory::Node*)), this, SLOT(showNodePropertiesDialog(GraphTheory::Node*))); connect(topLevel, SIGNAL(showEdgePropertiesDialog(GraphTheory::Edge*)), this, SLOT(showEdgePropertiesDialog(GraphTheory::Edge*))); // create widget setContent(path, component, topLevel); } View::~View() { } void View::setGraphDocument(GraphDocumentPtr document) { d->m_document = document; d->m_nodeModel->setDocument(d->m_document); d->m_edgeModel->setDocument(d->m_document); d->m_nodeTypeModel->setDocument(d->m_document); d->m_edgeTypeModel->setDocument(d->m_document); } GraphDocumentPtr View::graphDocument() const { return d->m_document; } void View::createNode(qreal x, qreal y, int typeIndex) { Q_ASSERT(typeIndex >= 0); Q_ASSERT(typeIndex < d->m_nodeTypeModel->rowCount()); NodePtr node = Node::create(d->m_document); node->setType(d->m_nodeTypeModel->type(typeIndex)); node->setX(x); node->setY(y); } void View::createEdge(Node *from, Node *to, int typeIndex) { Q_ASSERT(typeIndex >= 0); Q_ASSERT(typeIndex < d->m_edgeTypeModel->rowCount()); if (!from || !to) { return; } if (!from->isValid() || !to->isValid()) { return; } EdgePtr edge = Edge::create(from->self(), to->self()); edge->setType(d->m_edgeTypeModel->type(typeIndex)); } void View::deleteNode(GraphTheory::Node *node) { if (!node || !node->isValid()) { return; } node->destroy(); } void View::deleteEdge(GraphTheory::Edge *edge) { if (!edge || !edge->isValid()) { return; } edge->destroy(); } void View::showNodePropertiesDialog(Node *node) { QPointer dialog = new NodeProperties(); dialog->setData(node->self()); dialog->show(); // workaround: scene-drag not working with modal dialogs } void View::showEdgePropertiesDialog(Edge *edge) { QPointer dialog = new EdgeProperties(); dialog->setData(edge->self()); dialog->show(); // workaround: scene-drag not working with modal dialogs }