Skip to content

Commit

Permalink
cneben#248 Backport edges sample to support QuickQanava QML module.
Browse files Browse the repository at this point in the history
Signed-off-by: cneben <[email protected]>
  • Loading branch information
cneben committed Sep 22, 2024
1 parent 6ef30a8 commit 9df5e88
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 70 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ option(QUICK_QANAVA_BUILD_SAMPLES "Build QuickQanava samples" OFF)
#add_subdirectory(samples/connector)
#add_subdirectory(samples/cpp)
#add_subdirectory(samples/dataflow)
#add_subdirectory(samples/edges)
add_subdirectory(samples/edges)
add_subdirectory(samples/groups)
#add_subdirectory(samples/navigable)
#add_subdirectory(samples/nodes)
Expand Down
40 changes: 19 additions & 21 deletions samples/edges/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,38 @@ cmake_minimum_required(VERSION 3.16)

project(QuickQanava_sample_edges VERSION 2.5.0 LANGUAGES CXX)

# Configure Qt
find_package(Qt6 REQUIRED COMPONENTS Core Quick Qml Quick QuickControls2)
qt_standard_project_setup(REQUIRES 6.6)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Configure Qt
find_package(Qt6 REQUIRED COMPONENTS Core Quick Qml Quick QuickControls2)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:QT_QML_DEBUG>)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

if(NOT TARGET QuickQanava)
add_subdirectory(../../ quickqanava_build) # Use ../../src as quickqanava_build subdirectory
# see https://stackoverflow.com/questions/50408169/cmake-error-add-subdirectory-not-given-a-binary-directory/50408555
endif()

set(source_files
edges.cpp
qt_add_executable(sample_edges_exe edges.cpp)
qt_add_qml_module(SampleEdges
VERSION 1.0
URI SampleEdges
QML_FILES
SampleEdges.qml
Endings.qml
Curved.qml
Ortho.qml
OUTPUT_DIRECTORY SampleEdges
)

set (header_files)

add_executable(sample_edges ${source_files} edges.qrc)
qt6_add_resources(sample_edges "controls_conf"
PREFIX
"/"
FILES
"qtquickcontrols2.conf"
)
target_include_directories(sample_edges PUBLIC QuickQanava Qt${QT_VERSION_MAJOR}::QuickControls2)
target_link_libraries(sample_edges
include_directories(${CMAKE_CURRENT_SOURCE_DIR} "../../src")
set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE STRING "" FORCE)
target_link_libraries(sample_edges_exe PRIVATE
QuickQanava
QuickQanavaplugin
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::QuickControls2
)


3 changes: 1 addition & 2 deletions samples/edges/curved.qml → samples/edges/Curved.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import QtQuick.Shapes

import Qt.labs.platform

import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan
import QuickQanava as Qan

Item {
anchors.fill: parent
Expand Down
3 changes: 1 addition & 2 deletions samples/edges/endings.qml → samples/edges/Endings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import QtQuick.Controls.Material
import QtQuick.Layouts
import QtQuick.Shapes

import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan
import QuickQanava as Qan

Qan.GraphView {
id: graphView
Expand Down
3 changes: 1 addition & 2 deletions samples/edges/ortho.qml → samples/edges/Ortho.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import QtQuick.Controls.Material
import QtQuick.Layouts
import QtQuick.Shapes

import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan
import QuickQanava as Qan

Qan.GraphView {
id: graphView
Expand Down
9 changes: 4 additions & 5 deletions samples/edges/edges.qml → samples/edges/SampleEdges.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import QtQuick.Controls.Material
import QtQuick.Layouts
import QtQuick.Shapes

import QuickQanava 2.0 as Qan
import "qrc:/QuickQanava" as Qan
import QuickQanava as Qan

ApplicationWindow {
id: window
Expand All @@ -52,9 +51,9 @@ ApplicationWindow {
clip: true
Layout.fillWidth: true; Layout.fillHeight: true
currentIndex: tabBar.currentIndex
Item { Loader { anchors.fill: parent; source: "qrc:/curved.qml"} }
Item { Loader { anchors.fill: parent; source: "qrc:/endings.qml"} }
Item { Loader { anchors.fill: parent; source: "qrc:/ortho.qml"} }
Item { Loader { anchors.fill: parent; source: "Curved.qml"} }
Item { Loader { anchors.fill: parent; source: "Endings.qml"} }
Item { Loader { anchors.fill: parent; source: "Ortho.qml"} }
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions samples/edges/edges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//-----------------------------------------------------------------------------
// This file is a part of the QuickQanava software library.
//
// \file connector.cpp
// \file edges.cpp
// \author [email protected]
// \date 2017 03 06
//-----------------------------------------------------------------------------
Expand All @@ -43,18 +43,18 @@

using namespace qan;

#include <QQmlExtensionPlugin>
Q_IMPORT_QML_PLUGIN(QuickQanavaPlugin)

//-----------------------------------------------------------------------------
int main( int argc, char** argv )
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv); // Necessary for Qt.labs ColorDialog
QQuickStyle::setStyle("Material");
QQmlApplicationEngine engine;
engine.addPluginPath(QStringLiteral("../../src")); // Necessary only for development when plugin is not installed to QTDIR/qml
engine.addImportPath("../../src"); // Enable loading of ../../src/QuickQanava module
QuickQanava::initialize(&engine);
engine.load(QUrl("qrc:/edges.qml"));
engine.loadFromModule("SampleEdges", "SampleEdges");
return app.exec();
}
//-----------------------------------------------------------------------------
Expand Down
8 changes: 0 additions & 8 deletions samples/edges/edges.qrc

This file was deleted.

14 changes: 4 additions & 10 deletions samples/groups/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(QuickQanava_sample_groups VERSION 2.5.0 LANGUAGES CXX)

# Configure Qt
find_package(Qt6 REQUIRED COMPONENTS Core Quick Qml Quick QuickControls2)
qt_standard_project_setup(REQUIRES 6.5)
qt_standard_project_setup(REQUIRES 6.6)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
Expand All @@ -18,24 +18,18 @@ set(source_files
groups.cpp
)
qt_add_executable(sample_groups_exe groups.cpp)
qt_add_qml_module(sample_groups
qt_add_qml_module(SampleGroups
VERSION 1.0
URI sample_groups
URI SampleGroups
QML_FILES
SampleGroups.qml
OUTPUT_DIRECTORY sample_groups
OUTPUT_DIRECTORY SampleGroups
)
# qt_add_library(sample_groups STATIC)

include_directories(${CMAKE_CURRENT_SOURCE_DIR} "../../src")
# if(NOT TARGET QuickQanava)
#add_subdirectory(../../src QuickQanava_src)
# endif()

set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports CACHE STRING "" FORCE)

# add_executable(sample_groups ${source_files} groups.qrc)
# target_include_directories(sample_groups PUBLIC QuickQanava Qt${QT_VERSION_MAJOR}::QuickControls2)
target_link_libraries(sample_groups_exe PRIVATE
QuickQanava
QuickQanavaplugin
Expand Down
19 changes: 6 additions & 13 deletions samples/groups/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,14 @@ int main( int argc, char** argv )
QGuiApplication app(argc, argv);
QQuickStyle::setStyle("Material");
QQmlApplicationEngine engine;
engine.addImportPath("./QuickQanava");
engine.addImportPath("/home/b/projects/deliastrat.io/Holograph/third-party/QuickQanava/build/Desktop_Qt_6_7_2-Debug/src");
engine.addImportPath("/home/b/projects/deliastrat.io/Holograph/third-party/QuickQanava/build/Desktop_Qt_6_7_2-Debug/src/QuickQanava");
QString currentDir = QDir::currentPath();
qDebug() << "Current working directory:" << currentDir;
engine.addImportPath("../../src/");
//engine.addImportPath("/home/b/projects/deliastrat.io/Holograph/third-party/QuickQanava/build/Desktop_Qt_6_7_2-Debug/src");
//engine.addImportPath("/home/b/projects/deliastrat.io/Holograph/third-party/QuickQanava/build/Desktop_Qt_6_7_2-Debug/src/QuickQanava");

QuickQanava::initialize(&engine);
//engine.load(QUrl("qrc:/groups.qml"));

// FIXME #248 appears in recent QML sample, WTF ?
/*QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);*/
engine.loadFromModule("sample_groups", "SampleGroups");
engine.loadFromModule("SampleGroups", "SampleGroups");

return app.exec();
}
Expand Down

0 comments on commit 9df5e88

Please sign in to comment.