From 0bf8b321ae0c2d920919f7af1331270a815efaa2 Mon Sep 17 00:00:00 2001 From: Hane Date: Thu, 15 Aug 2024 18:07:13 +0200 Subject: [PATCH] wip: endpoint add/remove/role change bugfixes --- src/qt/qtclasses.cpp | 54 ++++++++++++++++++++++++-------------------- src/qt/qtclasses.h | 2 +- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 50a046a..8692897 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -753,14 +753,15 @@ void MainWindow::removeEndpointWidget(CustomWidgetEvent* ev){ //delete ews.at(index); delete ews.at(i); ews.at(i) = nullptr; - this->ewsUpdateTimer->start(); + //TODO: is a flattener really necessary? + //this->ewsUpdateTimer->start(); return; } void MainWindow::addEndpointWidget(CustomWidgetEvent* ev){ EndpointWidget* epw = new EndpointWidget(ev->payload, widget, this->ews.size()); //epw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - this->widgetLayout->addWidget(epw); + //this->widgetLayout->addWidget(epw); ews.push_back(epw); return; } @@ -911,6 +912,7 @@ HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent) { } void MainWindow::createLayout(QGridLayout *newLayout) { + log_debugcpp("createLayout"); widgetLayout->removeItem(lastRowSpacer); delete this->widgetLayout; widget->setLayout(newLayout); @@ -921,16 +923,15 @@ void MainWindow::createLayout(QGridLayout *newLayout) { for (EndpointWidget *epw : ews) { if (!epw) continue; else areEndpoints = true; - log_debugcpp("EPWidget positioning"); log_wdebugcpp(L"epw name: " + epw->getEndpointHandler()->getName()); - epw->setIndex(i); + //epw->setIndex(i); this->widgetLayout->addWidget(epw, i++, 0); } - if(areEndpoints) + if(areEndpoints) { + if (noEndpoints) { delete noEndpoints; noEndpoints = nullptr; } widgetLayout->addItem(lastRowSpacer, i, 0); - else { - if (noEndpoints) delete noEndpoints; - noEndpoints = new QLabel(STRING_NOENDPOINT, this); + } else { + if (!noEndpoints) noEndpoints = new QLabel(STRING_NOENDPOINT, this); widgetLayout->addWidget(noEndpoints, i, 0); } } @@ -1068,27 +1069,32 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { } void MainWindow::flushRoleChanges() { - std::pair change = roleBucketList.back(); - roleBucketList.pop_back(); - this->changeFrontDefaults(change.first, change.second); -} - -void MainWindow::changeFrontDefaults(Roles role, std::wstring endpointId) { - //Sigh... I hope to get this right when librole is done... - //todo: STILL BORKED. THEY'RE NOT FORFEITING THEIR OLD POSITION + //TODO: bucket list deque + std::pair change = roleBucketList.front(); + roleBucketList.erase(roleBucketList.begin()); + EndpointWidget *newDef = nullptr, *oldDef = nullptr; for (uint64_t i = 0; i < ews.size(); i++) { auto epw = this->ews.at(i); if (!epw) continue; - if (epw->getEndpointHandler()->getId() == endpointId) { + if (epw->getEndpointHandler()->getId() == change.second) { newDef = epw; - continue; } - if (epw->getEndpointHandler()->getRoles() & role) { + ews.at(i) = nullptr; + continue; + } + if (epw->getEndpointHandler()->getRoles() & change.first) { oldDef = epw; - continue; } + ews.at(i) = nullptr; + continue; + } } - + this->changeFrontDefaults(change.first, newDef, oldDef); +} + +void MainWindow::changeFrontDefaults(Roles role, EndpointWidget* newDef, EndpointWidget* oldDef) { + //Sigh... I hope to get this right when librole is done... + //todo: STILL BORKED. THEY'RE NOT FORFEITING THEIR OLD POSITION //debug if (role != Roles::ROLE_COMMUNICATIONS) return; if (newDef && !oldDef) { newDef->getDefaultRolesWidgets().at(role)->blockSignals(true); @@ -1099,7 +1105,7 @@ void MainWindow::changeFrontDefaults(Roles role, std::wstring endpointId) { if (newDefRoles == Roles::ROLE_ALL) { newDef->setIndex(0); this->ews[0] = newDef; - if (this->ews[1] && newDef->getEndpointHandler()->getId() == endpointId) this->ews[1] = nullptr; + //if (this->ews[1] && newDef->getEndpointHandler()->getId() == endpointId) this->ews[1] = nullptr; QCoreApplication::instance()->postEvent(newDef->getDefaultRolesWidgets().at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange)); } else if ((newDefRoles & Roles::ROLE_MULTIMEDIA) || (newDefRoles & Roles::ROLE_CONSOLE)){ @@ -1113,8 +1119,6 @@ void MainWindow::changeFrontDefaults(Roles role, std::wstring endpointId) { newDef->getDefaultRolesWidgets().at(role)->blockSignals(false); } else if (oldDef && newDef) { - this->ews.at(oldDef->getIndex()) = nullptr; - this->ews.at(newDef->getIndex()) = nullptr; newDef->getDefaultRolesWidgets().at(role)->blockSignals(true); newDef->getEndpointHandler()->assignRoles(role); QCoreApplication::instance()->postEvent(newDef->getDefaultRolesWidgets().at(role), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange)); @@ -1123,7 +1127,7 @@ void MainWindow::changeFrontDefaults(Roles role, std::wstring endpointId) { if (newDefRoles == Roles::ROLE_ALL) { newDef->setIndex(0); this->ews[0] = newDef; - if (this->ews[1] && newDef->getEndpointHandler()->getId() == endpointId) this->ews[1] = nullptr; + //if (this->ews[1] && newDef->getEndpointHandler()->getId() == endpointId) this->ews[1] = nullptr; QCoreApplication::instance()->postEvent(newDef->getDefaultRolesWidgets().at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange)); } else if ((newDefRoles & Roles::ROLE_MULTIMEDIA) || (newDefRoles & Roles::ROLE_CONSOLE)){ diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index c1b6c6e..8b77923 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -200,7 +200,7 @@ private slots: private: //std::vector *ephs; void flushRoleChanges(); - void changeFrontDefaults(Roles role, std::wstring endpointId); + void changeFrontDefaults(Roles role, EndpointWidget* newDef, EndpointWidget* oldDef); std::vector ews; std::vector> roleBucketList;