Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

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

    General and Desktop
    c++ qtreeview qstandarditemmo qstandarditem
    2
    2
    915
    Loading More Posts
    • 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
      fbengo last edited by fbengo

      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 Reply Quote 0
      • ValentinMichelet
        ValentinMichelet last edited by ValentinMichelet

        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 Reply Quote 0
        • First post
          Last post