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 convert a hierarchical print function into a hierarchical QStandardItemModel in C++ and Qt?
Forum Updated to NodeBB v4.3 + New Features

How to convert a hierarchical print function into a hierarchical QStandardItemModel in C++ and Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++qtreeviewqstandarditemmoqstandarditem
2 Posts 2 Posters 1.0k Views 1 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.
  • F Offline
    F Offline
    fbengo
    wrote on last edited by fbengo
    #1

    I have been trying for days to convert my print code into QStandardItemModel code, but I got stuck. I've created a row, which includes 4 attributes: attributeTag, attributeTagName, attributeVR, attributeLength.

    I need to convert the following print code into a QStandardItemModel:

    qDebug() << OFString(dicomObjectLevel, '>').c_str() << attributeTag << " " << attributeVR;
    

    Output print method:

     "(0040,a493)"   "CS"
     "(0040,a504)"   "SQ"
     "(fffe,e000)"   "na"
    > "(0008,0105)"   "CS"
    > "(0040,db00)"   "CS"
     "(0040,a730)"   "SQ"
     "(fffe,e000)"   "na"
    > "(0040,a010)"   "CS"
    > "(0040,a040)"   "CS"
    > "(0040,a043)"   "SQ"
    > "(fffe,e000)"   "na"
    >> "(0008,0100)"   "SH"
    >> "(0008,0102)"   "SH"
    >> "(0008,0104)"   "LO"
    > "(0040,a168)"   "SQ"
    > "(fffe,e000)"   "na"
    >> "(0008,0100)"   "SH"
    >> "(0008,0102)"   "SH"
    >> "(0008,0104)"   "LO"
    > "(0040,a730)"   "SQ"
    > "(fffe,e000)"   "na"
    >> "(0040,a010)"   "CS"
    >> "(0040,a040)"   "CS"
    >> "(0040,a043)"   "SQ"
    >> "(fffe,e000)"   "na"
    >>> "(0008,0100)"   "SH"
    >>> "(0008,0102)"   "SH"
    >>> "(0008,0104)"   "LO"
    >> "(0040,a168)"   "SQ"
    >> "(fffe,e000)"   "na"
    >>> "(0008,0100)"   "SH"
    >>> "(0008,0102)"   "SH"
    >>> "(0008,0104)"   "LO"
     "(fffe,e000)"   "na"
    > "(0040,a010)"   "CS"
    

    I tried many things but I cannot get it working correctly. What should I do in order to put all rows in their "correct" hiearchy? The arrow in front of each line in the output of the print function indicates the level. The level can be found in dicomObjectLevel

    My code:

    void MainController::printHierarchy(DcmObject* dataset)
    {
    	DcmStack stack;
    	QStandardItem* rootItem = m_model->invisibleRootItem();
    	while (dataset->nextObject(stack, OFTrue).good())
    	{
    		int dicomObjectLevel = (stack.card() / 2) - 1;
    		DcmObject* dicomObject = stack.top();
    		DcmTag dicomTag = dicomObject->getTag();
    		DcmVR dicomVR = dicomObject->getVR();
    
    		QString attributeTag = dicomTag.toString().c_str();
    		QString attributeTagName = dicomTag.getTagName();
    		QString attributeVR = dicomVR.getVRName();
    		QString attributeLength = QString::number(dicomObject->getLengthField());
    
    		QList<QStandardItem*> row = prepareRow(attributeTag, attributeTagName, attributeVR, attributeLength);
    
    		qDebug() << OFString(dicomObjectLevel, '>').c_str() << attributeTag << " " << attributeVR;
    	}
    }
    
    QList<QStandardItem *> MainController::prepareRow(const QString &elementTag, const QString &elementVR, const QString &elementLength, const QString &elementValue)
    {
        QList<QStandardItem *> rowItems;
        rowItems << new QStandardItem(elementTag);
        rowItems << new QStandardItem(elementVR);
        rowItems << new QStandardItem(elementLength);
    	rowItems << new QStandardItem(elementValue);
        return rowItems;
    }
    
    1 Reply Last reply
    0
    • ValentinMicheletV Offline
      ValentinMicheletV Offline
      ValentinMichelet
      wrote on last edited by ValentinMichelet
      #2

      Hi, welcome to Devnet.

      The things you have to understand with hierarchical model are:

      • everything can be done through items
      • use appendRows (or insertRows) to add one line containing several columns
      • create a hierarchy on the item that represents the first column with the above appendRows (for instance on "(fffe,e000)" but not on "SQ")
      • use appendRows (or insertRows) on top level instances only to your model (for instance "(0040,a493)" "CS", "(0040,a504)" "SQ", but not "(0008,0105)" "CS")

      To view your hierarchy, create a QTreeView and give it this model.

      If it's not clear enough, just let me know.

      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