remove WStandardItemModel row and append row to same WStandardItemModel??
Added by Mark Travis over 1 year ago
I'm trying to take a row out of a WStandardItemModel and append it to the end of the WStandardItemModel. ie, take row 5 out of a 100 row table, and append that row so that it becomes the new row 100.
Can this be done?
std::vector<std::unique_ptr<Wt::WStandardItem>> rowToMove;
rowToMove = shadowCopyItemModel->takeRow(i);
shadowCopyItemModel->appendRow(rowToMove);
I tried the following first, but that didn't work. Probably too much for all the templating to handle.
shadowCopyItemModel->append(shadowCopyItemModel->takeRow(i));
I'm getting an error that says:
In instantiation of member function 'std::vectorstd::unique_ptr
I'm not sure what the extra "::vector" in the error message is referring to.
Replies (4)
RE: remove WStandardItemModel row and append row to same WStandardItemModel?? - Added by Mark Travis over 1 year ago
I added std::move to the append, but I'm now getting an EXC_BAD_ACCESS while the widget tries to update the tableview and viewwidgets.
Seems like this should be the same mechanism as the sort routines, right?
RE: remove WStandardItemModel row and append row to same WStandardItemModel?? - Added by Roel Standaert over 1 year ago
I tried to reproduce your issue, but this code seems to run perfectly fine:
#include <Wt/WAny.h>
#include <Wt/WStandardItem.h>
#include <Wt/WStandardItemModel.h>
#include <memory>
constexpr int ROW_COUNT = 100;
int main()
{
auto model = std::make_shared<Wt::WStandardItemModel>();
for (int i = 0; i < ROW_COUNT; ++i) {
model->appendRow(std::make_unique<Wt::WStandardItem>(Wt::utf8("Row {1}").arg(i)));
}
model->appendRow(model->takeRow(20));
for (int i = 0; i < model->rowCount(); ++i) {
std::cout << i << ": " << Wt::asString(model->data(i, 0)).toUTF8() << '\n';
}
}
RE: remove WStandardItemModel row and append row to same WStandardItemModel?? - Added by Mark Travis over 1 year ago
Thanks Roel!
I just fixed this late last night.
To get around the perceived reason for the bug, I added:
Wt::WApplication::instance()->deferRendering();
Wt::WApplication::instance()->resumeRendering();
before and after the block.
I was debugging and was getting a nullptr on Wt::Application::instance(), which seemed to be the source of all.
Then I realized I was in the data prep phase at the beginning of a spawned thread where I'm using the WStandardItemModel as a mechanism to slice, dice, and manipulate the data before exporting it to a matrix for processing.
Instead of figuring out a way to block from another thread (which you had mentioned to me in another post), I realized I could move the block before the thread call back into the main loop, where it works perfectly now.
RE: remove WStandardItemModel row and append row to same WStandardItemModel?? - Added by Mark Travis over 1 year ago
The second "block" of that last sentence I mean "code block" instead of "blocking the updates". Sorry, should have finished my coffee before posting. :)