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/editorplugins/assignvalues/assignvalueswidget.ui b/libgraphtheory/editorplugins/assignvalues/assignvalueswidget.ui index f93e3489..7251e2cb 100644 --- a/libgraphtheory/editorplugins/assignvalues/assignvalueswidget.ui +++ b/libgraphtheory/editorplugins/assignvalues/assignvalueswidget.ui @@ -1,677 +1,677 @@ AssignValuesWidget 0 0 350 403 0 0 350 0 0 0 Assign Values - + Choose Properties 0 0 24 24 Show advanced options. true Assignment Method Enumerate Items Enumerate Alpha Enumerate Alpha-Numeric Assign Random Integers Assign Random Reals Assign Constant Value 0 0 115 QFormLayout::ExpandingFieldsGrow Start ID -100000 100000 Qt::Horizontal QFormLayout::AllNonFixedFieldsGrow Initial string a QFormLayout::ExpandingFieldsGrow Start ID -100000 0 Prefix QFormLayout::ExpandingFieldsGrow Lower Limit -99999 99999 1 Upper Limit Generator Seed 1 99999 1 -99999 99999 100 Lower Limit Upper Limit Generator Seed 3 -99999.990000000005239 0.000000000000000 3 -99999.990000000005239 99999.990000000005239 10.000000000000000 1 99999 1 QFormLayout::AllNonFixedFieldsGrow - + Constant true Overwrite existing values Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter QDialogButtonBox::Cancel|QDialogButtonBox::Ok 0 0 Qt::LeftToRight Nodes Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Property Name Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::LeftToRight Edges Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 0 0 Assign values to selected edges. true 0 0 Assign values to selected nodes. KLineEdit QLineEdit
klineedit.h
comboBoxMethod currentIndexChanged(int) stackedWidget setCurrentIndex(int) 153 141 308 165 buttonShowAdvanced toggled(bool) checkBoxOverwriteValues setVisible(bool) 299 21 253 374 buttonShowAdvanced toggled(bool) label setVisible(bool) 299 21 96 374 buttonShowAdvanced toggled(bool) spinBoxIntegerGeneratorSeed setVisible(bool) 299 21 124 327 buttonShowAdvanced toggled(bool) label_7 setVisible(bool) 299 21 61 323 buttonShowAdvanced toggled(bool) spinBoxFloatGeneratorSeed setVisible(bool) 299 21 69 260 buttonShowAdvanced toggled(bool) label_9 setVisible(bool) 299 21 61 323 buttonShowAdvanced toggled(bool) LabelInitialString setVisible(bool) 299 21 52 263 buttonShowAdvanced toggled(bool) LineEditInitialString setVisible(bool) 299 21 200 267
diff --git a/libgraphtheory/models/edgemodel.cpp b/libgraphtheory/models/edgemodel.cpp index 74f2e3a1..408562d2 100644 --- a/libgraphtheory/models/edgemodel.cpp +++ b/libgraphtheory/models/edgemodel.cpp @@ -1,174 +1,175 @@ /* * Copyright 2014 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 "edgemodel.h" #include "edge.h" #include "graphdocument.h" #include #include #include using namespace GraphTheory; class GraphTheory::EdgeModelPrivate { public: EdgeModelPrivate() : m_signalMapper(new QSignalMapper) { } ~EdgeModelPrivate() { m_signalMapper->deleteLater(); } void updateMappings() { int edges = m_document->edges().count(); for (int i = 0; i < edges; i++) { m_signalMapper->setMapping(m_document->edges().at(i).data(), i); } } GraphDocumentPtr m_document; QSignalMapper *m_signalMapper; }; EdgeModel::EdgeModel(QObject *parent) : QAbstractListModel(parent) , d(new EdgeModelPrivate) { connect(d->m_signalMapper, static_cast(&QSignalMapper::mapped), this, &EdgeModel::emitEdgeChanged); } EdgeModel::~EdgeModel() { } QHash< int, QByteArray > EdgeModel::roleNames() const { QHash roles; roles[IdRole] = "id"; roles[DataRole] = "dataRole"; return roles; } void EdgeModel::setDocument(GraphDocumentPtr document) { if (d->m_document == document) { return; } beginResetModel(); if (d->m_document) { d->m_document.data()->disconnect(this); } d->m_document = document; if (d->m_document) { connect(d->m_document.data(), &GraphDocument::edgeAboutToBeAdded, this, &EdgeModel::onEdgeAboutToBeAdded); connect(d->m_document.data(), &GraphDocument::edgeAdded, this, &EdgeModel::onEdgeAdded); connect(d->m_document.data(), &GraphDocument::edgesAboutToBeRemoved, this, &EdgeModel::onEdgesAboutToBeRemoved); connect(d->m_document.data(), &GraphDocument::edgesRemoved, this, &EdgeModel::onEdgesRemoved); } endResetModel(); } QVariant EdgeModel::data(const QModelIndex &index, int role) const { Q_ASSERT(d->m_document); if (!index.isValid()) { return QVariant(); } if (index.row() >= d->m_document->edges().count()) { return QVariant(); } EdgePtr const edge = d->m_document->edges().at(index.row()); switch(role) { case DataRole: return QVariant::fromValue(edge.data()); default: return QVariant(); } } int EdgeModel::rowCount(const QModelIndex &parent) const { if (!d->m_document) { return 0; } if (parent.isValid()) { return 0; } return d->m_document->edges().count(); } void EdgeModel::onEdgeAboutToBeAdded(EdgePtr edge, int index) { + Q_UNUSED(edge) //TODO add missing signals beginInsertRows(QModelIndex(), index, index); } void EdgeModel::onEdgeAdded() { d->updateMappings(); endInsertRows(); } void EdgeModel::onEdgesAboutToBeRemoved(int first, int last) { beginRemoveRows(QModelIndex(), first, last); } void EdgeModel::onEdgesRemoved() { endRemoveRows(); } void EdgeModel::emitEdgeChanged(int row) { emit edgeChanged(row); emit dataChanged(index(row, 0), index(row, 0)); } QVariant EdgeModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) { return QVariant(); } if (orientation == Qt::Vertical) { return QVariant(section + 1); } return QVariant(i18nc("@title:column", "Edge")); } diff --git a/libgraphtheory/models/nodemodel.cpp b/libgraphtheory/models/nodemodel.cpp index 0bf90f95..c9f9848f 100644 --- a/libgraphtheory/models/nodemodel.cpp +++ b/libgraphtheory/models/nodemodel.cpp @@ -1,169 +1,170 @@ /* * Copyright 2014 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 "nodemodel.h" #include "graphdocument.h" #include #include using namespace GraphTheory; class GraphTheory::NodeModelPrivate { public: NodeModelPrivate() : m_signalMapper(new QSignalMapper) { } ~NodeModelPrivate() { m_signalMapper->deleteLater(); } void updateMappings() { int nodes = m_document->nodes().count(); for (int i = 0; i < nodes; i++) { m_signalMapper->setMapping(m_document->nodes().at(i).data(), i); } } GraphDocumentPtr m_document; QSignalMapper *m_signalMapper; }; NodeModel::NodeModel(QObject *parent) : QAbstractListModel(parent) , d(new NodeModelPrivate) { connect(d->m_signalMapper, static_cast(&QSignalMapper::mapped), this, &NodeModel::emitNodeChanged); } NodeModel::~NodeModel() { } QHash< int, QByteArray > NodeModel::roleNames() const { QHash roles; roles[IdRole] = "id"; roles[DataRole] = "dataRole"; return roles; } void NodeModel::setDocument(GraphDocumentPtr document) { if (d->m_document == document) { return; } beginResetModel(); if (d->m_document) { d->m_document.data()->disconnect(this); } d->m_document = document; if (d->m_document) { connect(d->m_document.data(), &GraphDocument::nodeAboutToBeAdded, this, &NodeModel::onNodeAboutToBeAdded); connect(d->m_document.data(), &GraphDocument::nodeAdded, this, &NodeModel::onNodeAdded); connect(d->m_document.data(), &GraphDocument::nodesAboutToBeRemoved, this, &NodeModel::onNodesAboutToBeRemoved); connect(d->m_document.data(), &GraphDocument::nodesRemoved, this, &NodeModel::onNodesRemoved); } endResetModel(); } QVariant NodeModel::data(const QModelIndex &index, int role) const { Q_ASSERT(d->m_document); if (!index.isValid()) { return QVariant(); } if (index.row() >= d->m_document->nodes().count()) { return QVariant(); } NodePtr const node = d->m_document->nodes().at(index.row()); switch(role) { case IdRole: return node->id(); case DataRole: return QVariant::fromValue(node.data()); default: return QVariant(); } } int NodeModel::rowCount(const QModelIndex &parent) const { if (!d->m_document) { return 0; } if (parent.isValid()) { return 0; } return d->m_document->nodes().count(); } void NodeModel::onNodeAboutToBeAdded(NodePtr node, int index) { + Q_UNUSED(node) //TODO add missing signals beginInsertRows(QModelIndex(), index, index); } void NodeModel::onNodeAdded() { d->updateMappings(); endInsertRows(); } void NodeModel::onNodesAboutToBeRemoved(int first, int last) { beginRemoveRows(QModelIndex(), first, last); } void NodeModel::onNodesRemoved() { endRemoveRows(); } void NodeModel::emitNodeChanged(int row) { emit nodeChanged(row); emit dataChanged(index(row, 0), index(row, 0)); } QVariant NodeModel::headerData(int section, Qt::Orientation orientation, int role) const { if (role != Qt::DisplayRole) { return QVariant(); } if (orientation == Qt::Vertical) { return QVariant(section + 1); } return QVariant(i18nc("@title:column", "Node")); } 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 }