Cache macro segment widgets for each macro

This commit is contained in:
warmuptill
2025-05-18 12:53:31 +02:00
committed by WarmUpTill
parent cdc5d16e95
commit 56494480ba
3 changed files with 69 additions and 4 deletions

View File

@@ -46,6 +46,17 @@ MacroSegmentList::~MacroSegmentList()
_autoScroll = false;
_autoScrollThread.join();
}
const auto clearWidgetVector =
[](const std::vector<QWidget *> &widgets) {
for (auto widget : widgets) {
widget->deleteLater();
}
};
for (const auto &[_, widgets] : _widgetCache) {
clearWidgetVector(widgets);
}
}
static bool posIsInScrollbar(const QScrollBar *scrollbar, const QPoint &pos)
@@ -125,6 +136,38 @@ void MacroSegmentList::Clear(int idx) const
ClearLayout(_contentLayout, idx);
}
void MacroSegmentList::CacheCurrentWidgetsFor(const Macro *macro)
{
std::vector<QWidget *> result;
int idx = 0;
QLayoutItem *item;
while ((item = _contentLayout->takeAt(idx))) {
if (!item || !item->widget()) {
continue;
}
auto widget = item->widget();
widget->hide();
result.emplace_back(widget);
}
_widgetCache[macro] = result;
}
bool MacroSegmentList::PopulateWidgetsFromCache(const Macro *macro)
{
auto it = _widgetCache.find(macro);
if (it == _widgetCache.end()) {
return false;
}
for (auto widget : it->second) {
_contentLayout->addWidget(widget);
widget->show();
}
return true;
}
void MacroSegmentList::Highlight(int idx, QColor color)
{
auto item = _contentLayout->itemAt(idx);