diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-06-27 15:17:05 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-07-02 10:10:20 -0400 |
| commit | 093eb5650bdd010d9c779e64d3ca63682ba6ca19 (patch) | |
| tree | 6716d9b6599e94ccec6684ea4355f664e55de4c4 | |
| parent | 9ec0feba4395d492d814c03cf8be67a196bab36e (diff) | |
fixed problems with re-ordering tabs, realPos was never updated properly and it wasn't actually used everywhere
| -rw-r--r-- | src/modinfodialog.cpp | 40 | ||||
| -rw-r--r-- | src/modinfodialog.h | 2 |
2 files changed, 38 insertions, 4 deletions
diff --git a/src/modinfodialog.cpp b/src/modinfodialog.cpp index 676f3480..a5e8d8cd 100644 --- a/src/modinfodialog.cpp +++ b/src/modinfodialog.cpp @@ -170,6 +170,7 @@ ModInfoDialog::ModInfoDialog( } connect(ui->tabWidget, &QTabWidget::currentChanged, [&]{ onTabChanged(); }); + connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, [&]{ onTabMoved(); }); } ModInfoDialog::~ModInfoDialog() = default; @@ -249,12 +250,14 @@ ModInfoDialog::TabInfo* ModInfoDialog::currentTab() return nullptr; } - const auto i = static_cast<std::size_t>(index); - if (i >= m_tabs.size()) { - return nullptr; + for (auto& tabInfo : m_tabs) { + if (tabInfo.realPos == index) { + return &tabInfo; + } } - return &m_tabs[i]; + qCritical() << "tab index " << index << " not found"; + return nullptr; } void ModInfoDialog::update(bool firstTime) @@ -272,6 +275,7 @@ void ModInfoDialog::update(bool firstTime) } if (ui->tabWidget->currentIndex() == oldTab) { + // manually fire activated() because the tab index hasn't been changed if (auto* tabInfo=currentTab()) { tabInfo->tab->activated(); } @@ -600,6 +604,34 @@ void ModInfoDialog::onTabChanged() } } +void ModInfoDialog::onTabMoved() +{ + // reset + for (auto& tabInfo : m_tabs) { + tabInfo.realPos = -1; + } + + // for each tab in the widget + for (int i=0; i<ui->tabWidget->count(); ++i) { + const auto* w = ui->tabWidget->widget(i); + + bool found = false; + + // find the corresponding tab info + for (auto& tabInfo : m_tabs) { + if (tabInfo.widget == w) { + tabInfo.realPos = i; + found = true; + break; + } + } + + if (!found) { + qCritical() << "unknown tab at index " << i; + } + } +} + void ModInfoDialog::on_nextButton_clicked() { auto mod = m_mainWindow->nextModInList(); diff --git a/src/modinfodialog.h b/src/modinfodialog.h index 273af8c7..030b3f93 100644 --- a/src/modinfodialog.h +++ b/src/modinfodialog.h @@ -158,8 +158,10 @@ private: void switchToTab(ETabs id);
void reAddTabs(const std::vector<bool>& visibility, ETabs sel);
std::vector<QString> getOrderedTabNames() const;
+
void onOriginModified(std::size_t tabIndex, int originID);
void onTabChanged();
+ void onTabMoved();
template <class T>
std::unique_ptr<ModInfoDialogTab> createTab(int index)
|
