0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-29 01:49:49 +08:00

(EasyDescTreeWidget) Expanded files in blocks list remain expanded after refresh

This commit is contained in:
Victor Zarubkin 2016-11-20 18:34:31 +03:00
parent 75fff29ba5
commit a08b986418
2 changed files with 24 additions and 11 deletions

View File

@ -320,7 +320,7 @@ void EasyDescTreeWidget::keyPressEvent(QKeyEvent* _event)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void EasyDescTreeWidget::clearSilent(bool) void EasyDescTreeWidget::clearSilent(bool _global)
{ {
const QSignalBlocker b(this); const QSignalBlocker b(this);
@ -333,7 +333,13 @@ void EasyDescTreeWidget::clearSilent(bool)
::std::vector<QTreeWidgetItem*> topLevelItems; ::std::vector<QTreeWidgetItem*> topLevelItems;
topLevelItems.reserve(topLevelItemCount()); topLevelItems.reserve(topLevelItemCount());
for (int i = topLevelItemCount() - 1; i >= 0; --i) for (int i = topLevelItemCount() - 1; i >= 0; --i)
topLevelItems.push_back(takeTopLevelItem(i)); {
const bool expanded = !_global && topLevelItem(i)->isExpanded();
auto item = takeTopLevelItem(i);
if (expanded)
m_expandedFilesTemp.insert(item->text(DESC_COL_FILE_LINE).toStdString());
topLevelItems.push_back(item);
}
auto deleter_thread = ::std::thread([](decltype(topLevelItems) _items) { auto deleter_thread = ::std::thread([](decltype(topLevelItems) _items) {
for (auto item : _items) for (auto item : _items)
@ -364,7 +370,7 @@ void EasyDescTreeWidget::build()
f.setBold(true); f.setBold(true);
typedef ::std::unordered_map<::std::string, FileItems> Files; typedef ::std::unordered_map<::std::string, FileItems> Files;
Files m_files; Files fileItems;
m_items.resize(EASY_GLOBALS.descriptors.size()); m_items.resize(EASY_GLOBALS.descriptors.size());
memset(m_items.data(), 0, sizeof(void*) * m_items.size()); memset(m_items.data(), 0, sizeof(void*) * m_items.size());
@ -375,7 +381,7 @@ void EasyDescTreeWidget::build()
{ {
if (desc != nullptr) if (desc != nullptr)
{ {
auto& p = m_files[desc->file()]; auto& p = fileItems[desc->file()];
if (p.item == nullptr) if (p.item == nullptr)
{ {
p.item = new QTreeWidgetItem(); p.item = new QTreeWidgetItem();
@ -418,11 +424,14 @@ void EasyDescTreeWidget::build()
++id; ++id;
} }
for (auto& p : m_files) for (auto& p : fileItems)
{ {
addTopLevelItem(p.second.item); addTopLevelItem(p.second.item);
if (m_expandedFilesTemp.find(p.first) != m_expandedFilesTemp.end())
p.second.item->setExpanded(true);
} }
m_expandedFilesTemp.clear();
setSortingEnabled(true); setSortingEnabled(true);
sortByColumn(DESC_COL_FILE_LINE, Qt::AscendingOrder); sortByColumn(DESC_COL_FILE_LINE, Qt::AscendingOrder);
resizeColumnsToContents(); resizeColumnsToContents();
@ -780,7 +789,8 @@ void EasyDescWidget::keyPressEvent(QKeyEvent* _event)
void EasyDescWidget::build() void EasyDescWidget::build()
{ {
clear(); m_tree->clearSilent(false);
m_foundNumber->setText(QString("Found 0 matches"));
m_tree->build(); m_tree->build();
} }

View File

@ -49,6 +49,7 @@
#include <QTreeWidget> #include <QTreeWidget>
#include <QString> #include <QString>
#include <vector> #include <vector>
#include <unordered_set>
#include "easy/profiler.h" #include "easy/profiler.h"
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -88,9 +89,11 @@ class EasyDescTreeWidget : public QTreeWidget
typedef EasyDescTreeWidget This; typedef EasyDescTreeWidget This;
typedef ::std::vector<EasyDescWidgetItem*> Items; typedef ::std::vector<EasyDescWidgetItem*> Items;
typedef ::std::unordered_set<::std::string> ExpandedFiles;
protected: protected:
ExpandedFiles m_expandedFilesTemp;
Items m_items; Items m_items;
QString m_lastSearch; QString m_lastSearch;
QTreeWidgetItem* m_lastFound; QTreeWidgetItem* m_lastFound;