-----------------------------------------------------------------------------
| 120 | |
| 121 | //----------------------------------------------------------------------------- |
| 122 | int main( int argc, char** argv ) |
| 123 | { |
| 124 | QGuiApplication app(argc, argv); |
| 125 | QQuickStyle::setStyle("Material"); |
| 126 | QQmlApplicationEngine engine; |
| 127 | engine.addImportPath("../../src/"); |
| 128 | QuickQanava::initialize(&engine); |
| 129 | |
| 130 | qmlRegisterType<CustomGroup>("MyModule", 1, 0, "CustomGroup"); |
| 131 | qmlRegisterType<CustomNode>("MyModule", 1, 0, "CustomNode"); |
| 132 | qmlRegisterType<CustomGraph>("MyModule", 1, 0, "CustomGraph"); |
| 133 | qmlRegisterType<CustomEdge>("MyModule", 1, 0, "AbstractCustomEdge"); |
| 134 | |
| 135 | engine.load(QUrl("qrc:/cpp_sample.qml")); |
| 136 | |
| 137 | { // We can here customize QuickQanava graph topology _synchronously_ before the |
| 138 | // Qt/QML event loop starts |
| 139 | QPointer<CustomGraph> graph = nullptr; |
| 140 | for (const auto rootObject : engine.rootObjects()) { |
| 141 | graph = qobject_cast<CustomGraph*>(rootObject->findChild<QQuickItem *>("graph")); |
| 142 | if (graph) |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | if (graph) { |
| 147 | static constexpr qreal defaultWidth{40.}, defaultHeight{30.}; |
| 148 | static constexpr qreal xSpacing{50.}, ySpacing{30.}; |
| 149 | |
| 150 | static constexpr int array_size = 3; |
| 151 | qan::Node* nodes[array_size][array_size]; |
| 152 | for (int r = 0; r < array_size; r++) { |
| 153 | qreal nodeX = r * (defaultWidth + 2 * xSpacing ); |
| 154 | for (int c = 0; c < array_size; c++) { |
| 155 | qreal nodeY = c * (defaultHeight + 2 * ySpacing); |
| 156 | auto node = graph->insertCustomNode(); |
| 157 | node->getItem()->setMinimumSize({defaultWidth / 2., defaultHeight / 2.}); |
| 158 | node->getItem()->setRect({nodeX, nodeY, defaultWidth, defaultHeight}); |
| 159 | // Equivalent to: |
| 160 | //node->getItem()->setX(nodeX); |
| 161 | //node->getItem()->setY(nodeY); |
| 162 | //node->getItem()->setWidth(defaultWidth); |
| 163 | //node->getItem()->setHeight(defaultHeight); |
| 164 | //node->setLabel(QString::number(n++)); |
| 165 | nodes[r][c] = node; |
| 166 | } // for columns |
| 167 | } // for rows |
| 168 | auto group = graph->insertCustomGroup(); |
| 169 | group->getItem()->setRect({300, 200, 400, 250}); |
| 170 | |
| 171 | // Grouping nodes from c++ |
| 172 | graph->groupNode(group, nodes[0][0], nullptr, false); |
| 173 | |
| 174 | // NOTE: If the node is already on top of the group were we want to insert node, use transformPosition=true |
| 175 | // to convert node position from graphview coordinate system to group coordinate system. |
| 176 | // If the transformPosition=false is used, node will be grouped at (O, O) position of group, and |
| 177 | // it's position should be set after the call to groupNode(). |
| 178 | } |
| 179 | } |
nothing calls this directly
no test coverage detected