called externally and internally by signals
| 110 | // called externally |
| 111 | // and internally by signals |
| 112 | void DataSelectionTabs::callUpdateEntries() |
| 113 | { |
| 114 | // prevent infinite loop when calling 'setTabEnabled' -> currentTabChanged() -> update() |
| 115 | this->blockSignals(true); |
| 116 | RAIICleanup cleanup([&]() |
| 117 | { |
| 118 | this->blockSignals(false); |
| 119 | }); |
| 120 | |
| 121 | auto layer_ptr = getCurrentLayerData(tv_); // can be nullptr |
| 122 | |
| 123 | // becomes true if the currently visible tab has no data |
| 124 | bool auto_select = false; |
| 125 | // the order is important here. On auto-select, we will pick the highest one which has data to show! |
| 126 | Size highest_data_index = 0; // will pick spectra_view_widget_ if layer_ptr==nullptr |
| 127 | for (Size i = 0; i < tab_ptrs_.size(); ++i) |
| 128 | { |
| 129 | auto widget = dynamic_cast<QWidget*>(tab_ptrs_[i]); |
| 130 | bool has_data = tab_ptrs_[i]->hasData(layer_ptr); |
| 131 | setTabEnabled(i, has_data); // enable/disable depending on data |
| 132 | if (has_data) |
| 133 | { |
| 134 | highest_data_index = i; |
| 135 | } |
| 136 | if (!has_data && // the currently visible tab has no data --> select a new tab |
| 137 | widget->isVisible()) |
| 138 | { |
| 139 | auto_select = true; |
| 140 | } |
| 141 | } |
| 142 | // pick the highest tab which has data |
| 143 | if (auto_select) |
| 144 | { |
| 145 | setCurrentIndex(highest_data_index); |
| 146 | } |
| 147 | Size current_index = currentIndex(); |
| 148 | // update the currently visible tab (might be disabled if no data is shown) |
| 149 | tab_ptrs_[current_index]->updateEntries(layer_ptr); |
| 150 | } |
| 151 | |
| 152 | void DataSelectionTabs::currentTabChanged(int tab_index) |
| 153 | { |
no test coverage detected