2727
2828DataViewport::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
106120void DataViewport::saveStateToXml (XmlElement* xml)
@@ -111,25 +125,32 @@ void DataViewport::saveStateToXml(XmlElement* xml)
111125
112126void 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
0 commit comments