Skip to content

Commit bc7ec53

Browse files
committed
Remember expanded or collapsed wave data groups when upon waveform tree reordering
1 parent 24ef7eb commit bc7ec53

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

plugins/simulator/waveform_viewer/include/waveform_viewer/wave_tree_view.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace hal {
4949
{
5050
Q_OBJECT
5151
QList<QModelIndex> mItemOrder;
52+
QSet<u32> mExpandedGroups;
5253
QModelIndexList mContextIndexList;
5354
WaveDataList* mWaveDataList;
5455
WaveItemHash* mWaveItemHash;
@@ -68,11 +69,12 @@ namespace hal {
6869
Q_SIGNALS:
6970
void viewportHeightChanged(int height);
7071
void sizeChanged(int viewportHeight, int scrollbarMax, int scrollbarPos);
71-
void numberVisibleChanged(int nVisible, int scrollbarMax, int scrollbarPos);
72+
// void numberVisibleChanged(int nVisible, int scrollbarMax, int scrollbarPos); // unused
7273
void triggerUpdateWaveItems();
7374

7475
private Q_SLOTS:
75-
void handleExpandCollapse(const QModelIndex& index);
76+
void handleExpand(const QModelIndex& index);
77+
void handleCollapse(const QModelIndex& index);
7678
void handleContextMenuRequested(const QPoint& pos);
7779
void handleRemoveItem();
7880
void handleRenameItem();

plugins/simulator/waveform_viewer/src/wave_tree_model.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ namespace hal {
504504
int WaveTreeModel::waveIndex(const QModelIndex& index) const
505505
{
506506
WaveData* wd = item(index);
507-
if (!wd) return -1;
507+
if (!wd) return -99;
508508
if (dynamic_cast<WaveDataGroup*>(wd)) return -1;
509509
if (dynamic_cast<WaveDataBoolean*>(wd)) return -2;
510510
if (dynamic_cast<WaveDataTrigger*>(wd)) return -3;
@@ -743,7 +743,7 @@ namespace hal {
743743
// drop on group item
744744
if (dropParent.internalPointer() == mRoot)
745745
{
746-
dropRow(dropParent,0);
746+
dropRow(dropParent,row >= 0 ? row : 0);
747747
return true;
748748
}
749749
return false;

plugins/simulator/waveform_viewer/src/wave_tree_view.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace hal {
3333
setAcceptDrops(true);
3434
setContextMenuPolicy(Qt::CustomContextMenu);
3535
setItemDelegateForColumn(2,new WaveValueDelegate);
36-
connect(this,&QTreeView::expanded,this,&WaveTreeView::handleExpandCollapse);
37-
connect(this,&QTreeView::collapsed,this,&WaveTreeView::handleExpandCollapse);
36+
connect(this,&QTreeView::expanded,this,&WaveTreeView::handleExpand);
37+
connect(this,&QTreeView::collapsed,this,&WaveTreeView::handleCollapse);
3838
connect(this,&QTreeView::customContextMenuRequested,this,&WaveTreeView::handleContextMenuRequested);
3939
}
4040

@@ -387,9 +387,20 @@ namespace hal {
387387
QAbstractItemView::startDrag(supportedActions);
388388
}
389389

390-
void WaveTreeView::handleExpandCollapse(const QModelIndex& index)
390+
void WaveTreeView::handleExpand(const QModelIndex& index)
391391
{
392-
Q_UNUSED(index);
392+
const WaveTreeModel* wtm = static_cast<WaveTreeModel*>(model());
393+
int grpId = wtm->groupId(index);
394+
if (grpId >= 0) mExpandedGroups.insert(grpId);
395+
396+
reorder();
397+
}
398+
399+
void WaveTreeView::handleCollapse(const QModelIndex& index)
400+
{
401+
const WaveTreeModel* wtm = static_cast<WaveTreeModel*>(model());
402+
int grpId = wtm->groupId(index);
403+
if (grpId >= 0) mExpandedGroups.remove(grpId);
393404

394405
reorder();
395406
}
@@ -416,10 +427,13 @@ namespace hal {
416427
if (nVisible != mWaveItemHash->visibleEntries())
417428
{
418429
mWaveItemHash->setVisibleEntries(nVisible);
430+
431+
/* // signal not connected
419432
if (verticalScrollBar()->isVisible())
420433
Q_EMIT numberVisibleChanged(nVisible, verticalScrollBar()->maximum(), verticalScrollBar()->value());
421434
else
422435
Q_EMIT numberVisibleChanged(nVisible, -1, -1);
436+
*/
423437
}
424438
for (int i=0; i<nVisible; i++)
425439
{
@@ -477,6 +491,16 @@ namespace hal {
477491
auto it = notPlaced.find(wii);
478492
if (it != notPlaced.end()) notPlaced.erase(it);
479493
}
494+
495+
// restore expanded or collapsed group state
496+
int grpId = wtm->groupId(currentIndex);
497+
if (grpId >= 0)
498+
{
499+
if (mExpandedGroups.contains(grpId))
500+
expand(currentIndex);
501+
else
502+
collapse(currentIndex);
503+
}
480504
}
481505

482506
for (WaveItem* wi : notPlaced.values())

0 commit comments

Comments
 (0)