Well, after a lot of hair pulling, I got what I needed.
My first step was to create a Property
class. This class has functions to set or get a name string, a type string, a value double and a unit string.
Next, I updated the Node
class to include functions to add and remove Property
object pointers to a QList<Property *>
. Also included was a listProperties
function that returns all the Property
objects from a certain Node
.
After this, the function to populate the QTableWidget
with a certain Node
's properties was coded like this:
propertiesList = node->listMyProperties();
for (int row = 0; row < propertiesList.size(); ++row) {
Property *property = propertiesList.at(row);
addRow();
tableWidget->item(row, 0)->setData(Qt::DisplayRole, property->propertyName());
tableWidget->item(row, 1)->setData(Qt::DisplayRole, property->propertyType());
tableWidget->item(row, 2)->setData(Qt::DisplayRole, property->propertyValue());
tableWidget->item(row, 3)->setData(Qt::DisplayRole, property->propertyUnit());
}
And the addRow()
function:
void PropertiesDialog::addRow()
{
int row = tableWidget->rowCount();
tableWidget->insertRow(row);
QTableWidgetItem *item0 = new QTableWidgetItem;
item0->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tableWidget->setItem(row, 0, item0);
QTableWidgetItem *item1 = new QTableWidgetItem;
item1->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tableWidget->setItem(row, 1, item1);
QTableWidgetItem *item2 = new QTableWidgetItem;
item2->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tableWidget->setItem(row, 2, item2);
QTableWidgetItem *item3 = new QTableWidgetItem;
item3->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tableWidget->setItem(row, 3, item3);
tableWidget->setCurrentItem(item0);
}
This produces what I needed: to have a class to hold the property values related to each node, and present them on a QTableWidget
. Next step is to make the reverse path, meaning, when edits occur in the QTableWidget
, 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.