Reimplementation of QAbstractItemModel::setData
-
Hi,
I have a QTableView that display the content of a QSqlQueryModel. But now i need to merge some rows.
I decided to merge the content of the rows but i can't modify the QSqlQueryModel.I use a custom QSortFilterProxyModel.
But I don't know how to reimplement the setData function. I also need to reimplement the data function to get the content to merge.Thx
-
Hi @VRonin ,
I have rows in my TableView that represent real objects. Special objects can be created in pair. This is why i want to merge rows.
These special object have the same name but not the same length.Example :
At the begining i have two row with name XXXXX and length 5m and 10m.
At the end, i want to have one row with name XXXXX and length 5m + 10m.I hope I was clear in my explanations.
Thx
-
implemented here: http://pastebin.com/K3Xmquyz
example usage:
#include <QApplication> #include <QStandardItemModel> #include <QTableView> #include <QHBoxLayout> #include "mergeproxy.h" int main(int argc, char **argv) { QApplication app(argc,argv); QStandardItemModel baseModel; baseModel.insertRows(0, 5); baseModel.insertColumns(0, 2); baseModel.setHeaderData(0, Qt::Horizontal, "Col1"); baseModel.setHeaderData(1, Qt::Horizontal, "Col2"); baseModel.setData(baseModel.index(0, 0), "Test"); baseModel.setData(baseModel.index(0, 1), 1); baseModel.setData(baseModel.index(1, 0), "Test"); baseModel.setData(baseModel.index(1, 1), 2); baseModel.setData(baseModel.index(2, 0), "Test2"); baseModel.setData(baseModel.index(2, 1), 3); baseModel.setData(baseModel.index(3, 0), "Test2"); baseModel.setData(baseModel.index(3, 1), 4); baseModel.setData(baseModel.index(4, 0), "Alone"); baseModel.setData(baseModel.index(4, 1), 100); MergeProxy baseProxy; baseProxy.setSourceModel(&baseModel); baseProxy.setMergeKeyColumn(0); QWidget mainWidget; QTableView* savedView=new QTableView(&mainWidget); savedView->setModel(&baseModel); QTableView* loadedView=new QTableView(&mainWidget); loadedView->setModel(&baseProxy); QHBoxLayout* mainLay = new QHBoxLayout(&mainWidget); mainLay->addWidget(savedView); mainLay->addWidget(loadedView); mainWidget.show(); return app.exec(); }
-
Hi, it's me again.
I not sure i understood, in what function do you change the data ?
From what I understood, this is the MergeProxy::data function that edit the data.
Because now i'm working with a bigger table and more complex treatment.
I need to merge rows using two mergeKeyColumn.
Example :
Here the two last columns are the two mergeKeyColumn (first one is "pair_id" and second one is "id")
And "AKSA" from row 2 col 3 need to go at col 4.Result :
Thx
-