Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, after a lot of hair pulling, I got what I needed.</p> <p>My first step was to create a <code>Property</code> class. This class has functions to set or get a <em>name</em> string, a <em>type</em> string, a <em>value</em> double and a <em>unit</em> string.</p> <p>Next, I updated the <code>Node</code> class to include functions to add and remove <code>Property</code> object pointers to a <code>QList&lt;Property *&gt;</code>. Also included was a <code>listProperties</code> function that returns all the <code>Property</code> objects from a certain <code>Node</code>.</p> <p>After this, the function to populate the <code>QTableWidget</code> with a certain <code>Node</code>'s properties was coded like this:</p> <pre><code> propertiesList = node-&gt;listMyProperties(); for (int row = 0; row &lt; propertiesList.size(); ++row) { Property *property = propertiesList.at(row); addRow(); tableWidget-&gt;item(row, 0)-&gt;setData(Qt::DisplayRole, property-&gt;propertyName()); tableWidget-&gt;item(row, 1)-&gt;setData(Qt::DisplayRole, property-&gt;propertyType()); tableWidget-&gt;item(row, 2)-&gt;setData(Qt::DisplayRole, property-&gt;propertyValue()); tableWidget-&gt;item(row, 3)-&gt;setData(Qt::DisplayRole, property-&gt;propertyUnit()); } </code></pre> <p>And the <code>addRow()</code> function:</p> <pre><code>void PropertiesDialog::addRow() { int row = tableWidget-&gt;rowCount(); tableWidget-&gt;insertRow(row); QTableWidgetItem *item0 = new QTableWidgetItem; item0-&gt;setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); tableWidget-&gt;setItem(row, 0, item0); QTableWidgetItem *item1 = new QTableWidgetItem; item1-&gt;setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); tableWidget-&gt;setItem(row, 1, item1); QTableWidgetItem *item2 = new QTableWidgetItem; item2-&gt;setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); tableWidget-&gt;setItem(row, 2, item2); QTableWidgetItem *item3 = new QTableWidgetItem; item3-&gt;setTextAlignment(Qt::AlignRight | Qt::AlignVCenter); tableWidget-&gt;setItem(row, 3, item3); tableWidget-&gt;setCurrentItem(item0); } </code></pre> <p>This produces what I needed: to have a class to hold the property values related to each node, and present them on a <code>QTableWidget</code>. Next step is to make the reverse path, meaning, when edits occur in the <code>QTableWidget</code>, those changes should propagate to the class. Now I think I can find my way, hope this helps anyone trying to find something related. I'll also update the tags and maybe edit the title to make it more relevant/meaningful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload