table: integer data type support v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 10 Oct 2018 00:01:48 +0200
branchv_0
changeset 26 97847181b724
parent 25 da2e3739b197
child 27 8c5364450a46
table: integer data type support
src/RelpipeTableModel.h
--- a/src/RelpipeTableModel.h	Tue Oct 09 23:22:05 2018 +0200
+++ b/src/RelpipeTableModel.h	Wed Oct 10 00:01:48 2018 +0200
@@ -72,7 +72,22 @@
 		int column = attributeCounter % columnCount();
 		int row = attributeCounter / columnCount();
 		if (row >= records.size()) records.append(new QVector<QVariant>(columnCount()));
-		setData(index(row, column), QString::fromWCharArray(value.c_str()));
+
+		QString valueString = QString::fromWCharArray(value.c_str());
+		QVariant valueVariant;
+		boolean_t conversionOk = false;
+		if (attributes[column].getTypeId() == TypeId::INTEGER) {
+			valueVariant = valueString.toUInt(&conversionOk);
+		}
+		// TODO: boolean → checkboxes
+		// else if (attributes[column].getTypeId() == TypeId::BOOLEAN) {
+		//	valueVariant = L"true" == value;
+		//	conversionOk = true;
+		// }
+
+		if (!conversionOk) valueVariant = valueString;
+
+		setData(index(row, column), valueVariant);
 		if (column == 0) emit layoutChanged(); // FIXME: emit other signal ~ begin..., end..., rowsInserted(???  index(0,0), row, row);
 		attributeCounter++;
 	}