Results 1 to 9 of 9

Thread: Feasability study: Displaying a graph coded in C++ with QML ?

  1. #1
    Join Date
    Dec 2012
    Posts
    13

    Default Feasability study: Displaying a graph coded in C++ with QML ?

    Hello guys,

    I am starting working with QML and want to know if the following is feasable:

    I want to display a graph coded in C++ with QML in the following way:
    – nodes are represented by an icon (image file)
    – you can right click on an node and do some simple stuff like rename the node’s name
    – nodes are connected with lines and the graph is drawn in a suitable easy to visualize way

    I saw that there is GridView in QML, but not sure that you can draw lines between the elements or arrange them on the screen in a suitable way.

    Can you please give me an oppinion if this is feaseable with QML and which elements should I use ?

    Many thanks in advance !

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Dec 2012
    Posts
    13

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    Seems interesting ...

    But where to find that Canvas QML component:


    import "../../Canvas"

    import Qt 4.7

    Canvas {

    width:600
    ...
    ...

    ?

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    same website
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Dec 2012
    Posts
    13

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    Thanks, Yes I found it, run qmake on the src project, but still cannot run the graph.qml example with qmlviewer.
    It's not working ... Did you managed to run it ?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    Quote Originally Posted by amleto View Post
    The thing is this has nothing to do with QML. The graph is drawn using regular imperative code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Dec 2012
    Posts
    13

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    Any ideas if I could do it with QML ?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    If you implement all the elements you need in C++, export them to QML and use them then probably yes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Dec 2012
    Posts
    13

    Default Re: Feasability study: Displaying a graph coded in C++ with QML ?

    Here you can find the source code of the example:

    SourceCode_QML_Cpp.zip

    Hello,

    I have the following example - a QList of Nodes in ConfigurationModel .
    I want to bind the properties "QString nodeID" and "QString iconFilePath" beween the QML component Node and the C++ class Node.

    Unfortunetly the binding is not working - when you create the Node instances from C++, the properties of the correspondingly generated QML objects don't have the given values. They are empty. I cannot find where the issue comes from ... Could you please advise me, what I do wrong ?


    main.qml
    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. width: 500
    5. height: 500
    6.  
    7. Repeater {
    8. anchors.fill: parent
    9. model: configModel
    10. delegate: Node {}
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    Node.qml
    Qt Code:
    1. import QtQuick 1.0
    2. import NodeLib 1.0
    3.  
    4. Node {
    5. id: nodeDelegate
    6.  
    7. Image{
    8. id : nodeIcon
    9. source: nodeDelegate.iconFilePath
    10. }
    11.  
    12. Text {
    13. anchors.top: nodeIcon.bottom
    14. text: nodeDelegate.nodeID
    15. }
    16.  
    17. MouseArea {
    18. anchors.fill: parent
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "qmlapplicationviewer.h"
    3. #include <QDeclarativeContext>
    4. #include <QtDeclarative>
    5.  
    6. #include "ConfigurationModel.h"
    7.  
    8. Q_DECL_EXPORT int main(int argc, char *argv[])
    9. {
    10. QScopedPointer<QApplication> app(createApplication(argc, argv));
    11.  
    12. QDeclarativeView declarativeView;
    13. qmlRegisterType<Node>("NodeLib", 1, 0, "Node");
    14.  
    15. ConfigurationModel* p_configModel = ConfigurationModel::GetConfigModelInstance();
    16. p_configModel->addNodeInConfigurationModel(new Node("PanelXXXX", PLUG_IN, EVALUATION_BLOCK, "./ui-images/cutetube.png"));
    17. p_configModel->addNodeInConfigurationModel(new Node("PanelYYYY", PLUG_IN, EVALUATION_BLOCK, "./ui-images/cutetube.png"));
    18. Node *p_nodeZ = new Node("PanelZZZZ", PLUG_IN, EVALUATION_BLOCK, "./ui-images/cutetube.png");
    19. p_nodeZ->setNodeID("NODE ZZZZ");
    20. p_configModel->addNodeInConfigurationModel(p_nodeZ);
    21.  
    22. // if the configuration has been changed, you need to call setContextProperty() again to update the QML view
    23.  
    24. declarativeView.rootContext()->setContextProperty("configModel", ConfigurationModel::GetConfigModelInstance());
    25.  
    26. declarativeView.setSource(QUrl::fromLocalFile("qml/ConfigurationView/main.qml"));
    27. declarativeView.show();
    28.  
    29. return app->exec();
    30. }
    To copy to clipboard, switch view to plain text mode 


    Node.h
    Qt Code:
    1. #ifndef NODE_H
    2. #define NODE_H
    3.  
    4. #include <QString>
    5. #include <QList>
    6. #include <QDeclarativeItem>
    7.  
    8. #include "GlobalDeclarations.h"
    9.  
    10. // Inherit from QDeclarativeItem in order to override paint() method and to display links to parent nodes
    11. class Node : public QDeclarativeItem
    12. {
    13. Q_OBJECT
    14. Q_PROPERTY(QString iconFilePath READ getIconFilePath WRITE setIconFilePath NOTIFY iconFilePathChanged)
    15. Q_PROPERTY(QString nodeID READ getNodeID WRITE setNodeID NOTIFY nodeIDchanged)
    16.  
    17.  
    18. public:
    19. // Constructors
    20. Node();
    21. Node(QString nodeID, NodeType nodeType, PlugInType plugInType, QString iconFilePath);
    22.  
    23. QHash<int, QByteArray> roleNames() const;
    24. // Destructor
    25. ~Node();
    26.  
    27. QString getNodeID() const;
    28. Q_INVOKABLE bool setNodeID(const QString &nodeID);
    29.  
    30. QString getIconFilePath() const;
    31. Q_INVOKABLE bool setIconFilePath(const QString &iconFilePath);
    32.  
    33. void hide();
    34. void show();
    35.  
    36. void connectTo(Node* p_toNode);
    37. void disconnectFrom(Node* p_toNode);
    38. void removeNode();
    39.  
    40. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
    41.  
    42. signals:
    43. void nodeIDchanged(QString data);
    44. void iconFilePathChanged(QString data);
    45. void dataChanged();
    46.  
    47. protected:
    48. void addParent(Node* p_parentNode);
    49. const QList<Node*>& getParents() const;
    50. QList<Node*>& accessParents();
    51.  
    52. void addChild(Node* p_childNode);
    53. const QList<Node*>& getChildren() const;
    54. QList<Node*>& accessChildren();
    55.  
    56.  
    57. private:
    58. QString _nodeID;
    59. NodeType _nodeType;
    60. PlugInType _plugInType;
    61. QString _iconFilePath;
    62.  
    63. QList<Node*> _parents;
    64. QList<Node*> _children;
    65. };
    66.  
    67. #endif // NODE_H
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Converting to Model/View from hard-coded trees and tables
    By d_stranz in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2012, 17:46
  2. displaying a recorded signal as a graph
    By Aiswarya in forum Qwt
    Replies: 1
    Last Post: 21st April 2011, 09:03
  3. Qfile Question - hard coded path
    By fortyhideout12 in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2010, 20:50
  4. Displaying tooltip for points in the graph
    By Ankitha Varsha in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2008, 11:08
  5. Replies: 16
    Last Post: 4th October 2007, 22:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.