Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to integrate QGraphicsPolygonItem with QtXML.
Forum Updated to NodeBB v4.3 + New Features

How to integrate QGraphicsPolygonItem with QtXML.

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 2.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShrikantAmbade
    wrote on last edited by
    #1

    Hello Everyone,
    Need help for my project. I am working on import and export of XML file. For this I am using Qt XML. My Task is to read XML file so, I am trying for XML parser which will convert it into tree structure and further this generated tree structure I have to connect with the symbols like circle, squares etc. theses symbols are already designed by using QGraphicsPolygonItem class but I am getting how can I connect generated tree structre which is repsentation of my xml with these grahical element.

    Thank you so much in advance

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Well, technically it's up to you to parse that XML and generate QGraphicsPolygonItem from the data you get. There's not much more to it unless I misunderstood your question.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        Well, technically it's up to you to parse that XML and generate QGraphicsPolygonItem from the data you get. There's not much more to it unless I misunderstood your question.

        S Offline
        S Offline
        ShrikantAmbade
        wrote on last edited by
        #3

        @SGaist but how to generate QGraphicsPolygonItem?? I am am able to parse the XML file
        following is the code for reading XML file just a little example this code I got and understood it. But now suppose I want to connect root element with the one of the graphical element like square. How to do that? please help with little code if you can just as example

        //DOM methode of reading XML file

        void ListElements(QDomElement root, QString tagname, QString attribute)
        {
        QDomNodeList items = root.elementsByTagName(tagname);

        qDebug()<<"Total items = " << items.count();
        for(int i=0; i<items.count(); i++){
            QDomNode itemnode = items.at(i);
        
            //convert to element
            if(itemnode.isElement())
            {
                QDomElement itemele = itemnode.toElement();
                qDebug()<<itemele.attribute(attribute);
            }
        }
        

        }

        int main(int argc, char *argv[])
        {
        QCoreApplication a(argc, argv);

        QDomDocument document;
        
        // Load the XML file or open the XML file
        
        QFile file("C:/Users/Shri/Desktop/QT/Myxmlexample/writexml.xml");
        if(!file.open(QIODevice::ReadOnly |QIODevice::Text)){
            qDebug() << "Failed to open the file";
            return -1;
        }
        else{
            if(!document.setContent(&file)){
                qDebug()<<"Failed to get the content";
                return -1;
            }
            file.close();
        }
        
        //get the root elements
        QDomElement root = document.firstChildElement();
        
        //List the book element
        ListElements(root,"Book","Name");
        
        qDebug()<<"\r\n More Advance \r\n";
        
        QDomNodeList books = root.elementsByTagName("Book");
        for(int i=0; i<books.count();i++)
        {
            QDomNode booknode = books.at(i);
            //convert to an element
            if(booknode.isElement())
            {
                QDomElement book = booknode.toElement();
                qDebug()<<"Chapter in " << book.attribute("Name");
                ListElements(book,"Chapter","Name");
            }
        }
        
        qDebug()<<"End Success";
        
        
        
        
        return a.exec();
        

        }

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Well, technically it's up to you to parse that XML and generate QGraphicsPolygonItem from the data you get. There's not much more to it unless I misunderstood your question.

          S Offline
          S Offline
          ShrikantAmbade
          wrote on last edited by
          #4

          @SGaist This is GUI application on touch screen

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Being on a touch screen or desktop has no influence here.

            In order to help get started (except taking a look at the Graphics View Framework documentation)
            What do you get from your XML ? Geometries ? Coordinates ? Do you want to represent an arbitrary piece of data with some sort of picture ? e.g. a node represents a book so you want to draw a book to represent it on your scene ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            S 1 Reply Last reply
            0
            • SGaistS SGaist

              Being on a touch screen or desktop has no influence here.

              In order to help get started (except taking a look at the Graphics View Framework documentation)
              What do you get from your XML ? Geometries ? Coordinates ? Do you want to represent an arbitrary piece of data with some sort of picture ? e.g. a node represents a book so you want to draw a book to represent it on your scene ?

              S Offline
              S Offline
              ShrikantAmbade
              wrote on last edited by
              #6

              @SGaist Thank you so much.

              For example: XML contain text data like root element and then inside that some other element and so on. When I read XML file and parse it, it store it into tree data structure with the help of DOM parser. Now after this I have root element store somewhere and also complete hierarchy is build accordingly into tree. On the other hand I have Graphical element which are just dummy symbols like circle (While I called set, this is just a name of symbol), Square (Which is represent tuples) etc. But these symbol have no identity or semantics now and Semantics is in XML which I save into Tree so I want to some how connect this two so that When I import XML file then this symbols connect with each other according to the data in XML.

              I hope you understand what I want to say.. I am sorry I am bad in explaining my concept but I tried.
              Many Thanks once again

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Yes I do.

                For the linking part, take a look at the "Elastic Nodes" example.

                As for translating your XML, you can create a subclass of QGraphicsItem which will contain the type of data it represent and draw itself accordingly.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply
                0
                • SGaistS SGaist

                  Yes I do.

                  For the linking part, take a look at the "Elastic Nodes" example.

                  As for translating your XML, you can create a subclass of QGraphicsItem which will contain the type of data it represent and draw itself accordingly.

                  S Offline
                  S Offline
                  ShrikantAmbade
                  wrote on last edited by
                  #8

                  @SGaist Thank you so much. Can you please give me little example any code so that I can understand it better as I am new in programming and trying to do it at my level

                  Many Thanks

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi
                    Maybe you can start with
                    http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html

                    S 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      Hi
                      Maybe you can start with
                      http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html

                      S Offline
                      S Offline
                      ShrikantAmbade
                      wrote on last edited by
                      #10

                      @mrjj Thank you I will look into it

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved