0
votes

In wx-widget we can undo any event by calling VETO().

Here i am doing my first GUI in QT. I have created a new node test case 3.

Now i want that selection on tree should be only allowed to changed till i have not saved this new node. If i have not saved this node at least once, selection change should revert back to this unsaved node test case 3. To indicate that i have saved the node i am using a global variable signal.

How can i achive it?

I tried something like this but no result.

Inside selection changed event handler when new node created signal is set, then if i change the treewidget selection i am trying to set the selection of the treewidget to the last item of the treewidget:

QPoint prevPoint;
QModelIndex index;
int count = ui->treeWidgetLeft->topLevelItemCount();
//prevPoint.setX(currentXmlRootNodeNumber +1 );
prevPoint.setX(count);
prevPoint.setY(0);
index = ui->treeWidgetLeft->indexAt(prevPoint);
abortEvent = TRUE;
ui->treeWidgetLeft->selectionModel()->select(index ,QItemSelectionModel::Select);

And check at begning of selection changed event handler:

if (abortEvent) {
    abortEvent = false;
    return;
}

enter image description here

1

1 Answers

2
votes

That's not how the users expect treewidget and selections to work. I suggest that you reconsider the workflow of your program.

What if you let the user change the test case without saving when the user selects another test case from the treewidget? Show a messagebox and ask if the user wants to save. Then save/discard and change the test case to the one the user clicked.

Or remove the "Save" button completely. Always save the data the user enters to the test case. If you like, you could add an undo button instead. It would restore the test case to the state it was when the user selected it. That is quite easy to implement, just create a copy of the test case when editing starts and revert to that if the user selects the undo operation.

And I really recommend that you change the "Perv" button to "Prev".