0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

(GUI) Blocks/files list widget search fix: files are highlighted too

This commit is contained in:
Victor Zarubkin 2016-12-21 23:19:22 +03:00
parent 6d59c53f7a
commit 4078fe2a4a
2 changed files with 35 additions and 32 deletions

View File

@ -199,6 +199,7 @@ bool EasyDescWidgetItem::operator < (const Parent& _other) const
EasyDescTreeWidget::EasyDescTreeWidget(QWidget* _parent) EasyDescTreeWidget::EasyDescTreeWidget(QWidget* _parent)
: Parent(_parent) : Parent(_parent)
, m_lastFound(nullptr) , m_lastFound(nullptr)
, m_lastSearchColumn(-1)
, m_searchColumn(DESC_COL_NAME) , m_searchColumn(DESC_COL_NAME)
, m_bLocked(false) , m_bLocked(false)
{ {
@ -318,6 +319,7 @@ void EasyDescTreeWidget::clearSilent(bool _global)
m_lastFound = nullptr; m_lastFound = nullptr;
m_lastSearch.clear(); m_lastSearch.clear();
m_highlightItems.clear();
m_items.clear(); m_items.clear();
::std::vector<QTreeWidgetItem*> topLevelItems; ::std::vector<QTreeWidgetItem*> topLevelItems;
@ -557,6 +559,15 @@ void EasyDescTreeWidget::onSelectedBlockChange(uint32_t _block_index)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void EasyDescTreeWidget::resetHighlight()
{
for (auto item : m_highlightItems) {
for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i)
item->setBackground(i, Qt::NoBrush);
}
m_highlightItems.clear();
}
void EasyDescTreeWidget::loadSettings() void EasyDescTreeWidget::loadSettings()
{ {
QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME); QSettings settings(::profiler_gui::ORGANAZATION_NAME, ::profiler_gui::APPLICATION_NAME);
@ -585,16 +596,12 @@ int EasyDescTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags)
{ {
if (_str.isEmpty()) if (_str.isEmpty())
{ {
for (auto item : m_items) resetHighlight();
{ m_lastSearchColumn = m_searchColumn;
for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i)
item->setBackground(i, Qt::NoBrush);
}
return 0; return 0;
} }
const bool isNewSearch = (m_lastSearch != _str); const bool isNewSearch = (m_lastSearchColumn != m_searchColumn || m_lastSearch != _str);
auto itemsList = findItems(_str, Qt::MatchContains | Qt::MatchRecursive | _flags, m_searchColumn); auto itemsList = findItems(_str, Qt::MatchContains | Qt::MatchRecursive | _flags, m_searchColumn);
if (!isNewSearch) if (!isNewSearch)
@ -605,9 +612,6 @@ int EasyDescTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags)
decltype(m_lastFound) next = nullptr; decltype(m_lastFound) next = nullptr;
for (auto item : itemsList) for (auto item : itemsList)
{ {
if (item->parent() == nullptr)
continue;
if (stop) if (stop)
{ {
next = item; next = item;
@ -626,18 +630,16 @@ int EasyDescTreeWidget::findNext(const QString& _str, Qt::MatchFlags _flags)
} }
else else
{ {
for (auto item : m_items) resetHighlight();
{
for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i)
item->setBackground(i, Qt::NoBrush);
}
m_lastSearchColumn = m_searchColumn;
m_lastSearch = _str; m_lastSearch = _str;
m_lastFound = !itemsList.empty() ? itemsList.front() : nullptr; m_lastFound = !itemsList.empty() ? itemsList.front() : nullptr;
for (auto item : itemsList) for (auto item : itemsList)
{ {
if (item->parent() != nullptr) for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i) m_highlightItems.push_back(item);
for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i)
item->setBackgroundColor(i, QColor::fromRgba(0x80000000 | (0x00ffffff & ::profiler::colors::Yellow))); item->setBackgroundColor(i, QColor::fromRgba(0x80000000 | (0x00ffffff & ::profiler::colors::Yellow)));
} }
} }
@ -655,16 +657,12 @@ int EasyDescTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags)
{ {
if (_str.isEmpty()) if (_str.isEmpty())
{ {
for (auto item : m_items) resetHighlight();
{ m_lastSearchColumn = m_searchColumn;
for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i)
item->setBackground(i, Qt::NoBrush);
}
return 0; return 0;
} }
const bool isNewSearch = (m_lastSearch != _str); const bool isNewSearch = (m_lastSearchColumn != m_searchColumn || m_lastSearch != _str);
auto itemsList = findItems(_str, Qt::MatchContains | Qt::MatchRecursive | _flags, m_searchColumn); auto itemsList = findItems(_str, Qt::MatchContains | Qt::MatchRecursive | _flags, m_searchColumn);
if (!isNewSearch) if (!isNewSearch)
@ -674,9 +672,6 @@ int EasyDescTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags)
decltype(m_lastFound) prev = nullptr; decltype(m_lastFound) prev = nullptr;
for (auto item : itemsList) for (auto item : itemsList)
{ {
if (item->parent() == nullptr)
continue;
if (item == m_lastFound) if (item == m_lastFound)
break; break;
@ -692,18 +687,16 @@ int EasyDescTreeWidget::findPrev(const QString& _str, Qt::MatchFlags _flags)
} }
else else
{ {
for (auto item : m_items) resetHighlight();
{
for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i)
item->setBackground(i, Qt::NoBrush);
}
m_lastSearchColumn = m_searchColumn;
m_lastSearch = _str; m_lastSearch = _str;
m_lastFound = !itemsList.empty() ? itemsList.front() : nullptr; m_lastFound = !itemsList.empty() ? itemsList.front() : nullptr;
for (auto item : itemsList) for (auto item : itemsList)
{ {
if (item->parent() != nullptr) for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i) m_highlightItems.push_back(item);
for (int i = 0; i < DESC_COL_COLUMNS_NUMBER; ++i)
item->setBackgroundColor(i, QColor::fromRgba(0x80000000 | (0x00ffffff & ::profiler::colors::Yellow))); item->setBackgroundColor(i, QColor::fromRgba(0x80000000 | (0x00ffffff & ::profiler::colors::Yellow)));
} }
} }
@ -825,6 +818,11 @@ void EasyDescWidget::keyPressEvent(QKeyEvent* _event)
_event->accept(); _event->accept();
} }
void EasyDescWidget::contextMenuEvent(QContextMenuEvent* _event)
{
m_tree->contextMenuEvent(_event);
}
void EasyDescWidget::build() void EasyDescWidget::build()
{ {
m_tree->clearSilent(false); m_tree->clearSilent(false);

View File

@ -89,14 +89,17 @@ class EasyDescTreeWidget : public QTreeWidget
typedef EasyDescTreeWidget This; typedef EasyDescTreeWidget This;
typedef ::std::vector<EasyDescWidgetItem*> Items; typedef ::std::vector<EasyDescWidgetItem*> Items;
typedef ::std::vector<QTreeWidgetItem*> TreeItems;
typedef ::std::unordered_set<::std::string> ExpandedFiles; typedef ::std::unordered_set<::std::string> ExpandedFiles;
protected: protected:
ExpandedFiles m_expandedFilesTemp; ExpandedFiles m_expandedFilesTemp;
Items m_items; Items m_items;
TreeItems m_highlightItems;
QString m_lastSearch; QString m_lastSearch;
QTreeWidgetItem* m_lastFound; QTreeWidgetItem* m_lastFound;
int m_lastSearchColumn;
int m_searchColumn; int m_searchColumn;
bool m_bLocked; bool m_bLocked;
@ -135,6 +138,7 @@ private:
// Private methods // Private methods
void resetHighlight();
void loadSettings(); void loadSettings();
void saveSettings(); void saveSettings();
@ -164,6 +168,7 @@ public:
explicit EasyDescWidget(QWidget* _parent = nullptr); explicit EasyDescWidget(QWidget* _parent = nullptr);
virtual ~EasyDescWidget(); virtual ~EasyDescWidget();
void keyPressEvent(QKeyEvent* _event) override; void keyPressEvent(QKeyEvent* _event) override;
void contextMenuEvent(QContextMenuEvent* _event) override;
public: public: