Skip to content

Commit 0e8f364

Browse files
committed
Improve tab reloading
1 parent 547c8ae commit 0e8f364

3 files changed

Lines changed: 46 additions & 20 deletions

File tree

Source/Processors/Editors/VisualizerEditor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ void VisualizerEditor::setActiveTabId (int tindex)
392392

393393
void VisualizerEditor::removeTab (int tindex)
394394
{
395+
396+
//std::cout << "Removing tab for " << nodeId << std::endl;
395397
AccessClass::getDataViewport()->destroyTab (tindex);
396398
tabIndex = -1;
397399
}
@@ -402,5 +404,7 @@ int VisualizerEditor::addTab (String textOfTab, Visualizer* contentComponent)
402404
tabText = textOfTab;
403405
tabIndex = AccessClass::getDataViewport()->addTabToDataViewport (textOfTab, contentComponent);
404406

407+
//std::cout << "Adding tab for " << nodeId << " at " << tabIndex << std::endl;
408+
405409
return tabIndex;
406410
}

Source/UI/DataViewport.cpp

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@
2727

2828
DataViewport::DataViewport() :
2929
TabbedComponent(TabbedButtonBar::TabsAtRight),
30-
tabDepth(32), tabIndex(0), shutdown(false)
30+
tabDepth(32), tabIndex(1), shutdown(false)
3131
{
3232

33-
tabArray.clear();
34-
tabNameMap.clear();
35-
tabComponentMap.clear();
36-
3733
setTabBarDepth(tabDepth);
3834
setIndent(8); // gap to leave around the edge
3935
// of the content component
@@ -51,7 +47,7 @@ int DataViewport::addTabToDataViewport(String name,
5147
if (tabArray.size() == 0)
5248
setVisible(true);
5349

54-
tabIndex++;
50+
5551

5652
addTab(name, Colours::lightgrey, component, false, tabIndex);
5753

@@ -62,18 +58,28 @@ int DataViewport::addTabToDataViewport(String name,
6258

6359
tabArray.add(tabIndex);
6460

65-
LOGDD("Data Viewport adding tab with index ", tabIndex);
61+
//std::cout << "Tab Array: ";
62+
// for (int i = 0; i < tabArray.size(); i++)
63+
// std::cout << tabArray[i] << " ";
64+
// std::cout << std::endl;
65+
66+
LOGD("Data Viewport adding tab with index ", tabIndex);
6667

6768
setCurrentTabIndex(tabArray.size()-1);
6869

69-
return tabIndex;
70+
tabIndex++;
71+
72+
return tabIndex - 1;
7073

7174
}
7275

73-
void DataViewport::addTabAtIndex(int tabIndex, String tabName, Component* tabComponent)
76+
void DataViewport::addTabAtIndex(int tabIndex_, String tabName, Component* tabComponent)
7477
{
75-
tabNameMap.emplace(tabIndex, tabName);
76-
tabComponentMap.emplace(tabIndex, tabComponent);
78+
79+
savedTabIndices.add(tabIndex_);
80+
savedTabComponents.add(tabComponent);
81+
savedTabNames.add(tabName);
82+
7783
}
7884

7985

@@ -92,7 +98,7 @@ void DataViewport::destroyTab(int index)
9298
int newIndex = tabArray.indexOf(index);
9399

94100
tabArray.remove(newIndex);
95-
tabIndex--;
101+
//tabIndex--;
96102

97103
removeTab(newIndex);
98104

@@ -101,6 +107,14 @@ void DataViewport::destroyTab(int index)
101107

102108
setCurrentTabIndex(tabArray.size()-1);
103109

110+
//std::cout << "Tab Array: ";
111+
// for (int i = 0; i < tabArray.size(); i++)
112+
// std::cout << tabArray[i] << " ";
113+
//std::cout << std::endl;
114+
115+
if (tabArray.size() == 2) // just graph and info tab left
116+
tabIndex = 3;
117+
104118
}
105119

106120
void DataViewport::saveStateToXml(XmlElement* xml)
@@ -111,25 +125,32 @@ void DataViewport::saveStateToXml(XmlElement* xml)
111125

112126
void DataViewport::loadStateFromXml(XmlElement* xml)
113127
{
114-
for (const auto& tab : tabNameMap)
128+
129+
std::vector<int> tabOrder(savedTabIndices.size());
130+
std::iota(tabOrder.begin(), tabOrder.end(), 0); //Initializing
131+
sort(tabOrder.begin(), tabOrder.end(), [&](int i, int j)
132+
{return savedTabIndices[i] < savedTabIndices[j]; });
133+
134+
for (int i = 0; i < tabOrder.size(); i++)
115135
{
116-
// LOGC("********* ADDING ", tab.second, " to index ", tab.first, " ", tabComponentMap[tab.first]->getName());
117-
addTabToDataViewport(tab.second, tabComponentMap[tab.first]);
136+
tabIndex = savedTabIndices[tabOrder[i]];
137+
addTabToDataViewport(savedTabNames[tabOrder[i]], savedTabComponents[tabOrder[i]]);
118138
}
119139

120140
for (auto* xmlNode : xml->getChildIterator())
121141
{
122142
if (xmlNode->hasTagName("DATAVIEWPORT"))
123143
{
124144
int index = xmlNode->getIntAttribute("selectedTab", -1);
125-
if (index != -1)
145+
if (index != -1)
126146
selectTab(index);
127147
}
128148

129149
}
130150

131-
tabNameMap.clear();
132-
tabComponentMap.clear();
151+
savedTabIndices.clear();
152+
savedTabComponents.clear();
153+
savedTabNames.clear();
133154

134155
}
135156

Source/UI/DataViewport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ class DataViewport : public TabbedComponent
8585
Array<int> tabArray;
8686

8787
/** Maps processors to their respective tabs within the DataViewport. */
88-
std::map<int, String> tabNameMap;
89-
std::map<int, Component*> tabComponentMap;
88+
Array<int> savedTabIndices;
89+
Array<String> savedTabNames;
90+
Array<Component*> savedTabComponents;
9091

9192
void paint(Graphics& g);
9293
int tabDepth;

0 commit comments

Comments
 (0)