Skip to content

Commit 55d60cb

Browse files
Implemented #1077
1 parent cc919b0 commit 55d60cb

8 files changed

Lines changed: 115 additions & 11 deletions

File tree

qtgui/exe/GeoDmsGuiQt.vcxproj.filters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@
121121
<ClInclude Include="src\StatisticsBrowser.h">
122122
<Filter>Header Files</Filter>
123123
</ClInclude>
124-
<ClInclude Include="src\UpdatableBrowser.h">
125-
<Filter>Header Files</Filter>
126-
</ClInclude>
127124
<ClInclude Include="src\DmsGuiParameters.h">
128125
<Filter>Header Files</Filter>
129126
</ClInclude>
@@ -133,6 +130,9 @@
133130
<ClInclude Include="src\DmsSplashScreen.h">
134131
<Filter>Header Files</Filter>
135132
</ClInclude>
133+
<ClInclude Include="src\UpdatableBrowser.h">
134+
<Filter>Header Files</Filter>
135+
</ClInclude>
136136
</ItemGroup>
137137
<ItemGroup>
138138
<ResourceCompile Include="GeoDmsGuiQt.rc" />

qtgui/exe/src/DmsActions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ void createDmsActions() {
7171
main_window->m_edit_menu->addAction(main_window->m_edit_config_source_action.get());
7272
main_window->m_edit_config_source_action->setShortcut(QKeySequence(QObject::tr("Ctrl+E")));
7373

74+
// find TreeItem
75+
main_window->m_find_treeitem_action = std::make_unique<QAction>(QObject::tr("&Find TreeItem"));
76+
main_window->connect(main_window->m_find_treeitem_action.get(), &QAction::triggered, main_window, &MainWindow::findTreeItem);
77+
main_window->m_edit_menu->addAction(main_window->m_find_treeitem_action.get());
78+
main_window->m_find_treeitem_action->setShortcut(QKeySequence(QObject::tr("Ctrl+F")));
79+
7480
// update treeitem
7581
main_window->m_update_treeitem_action = std::make_unique<QAction>(QObject::tr("&Update TreeItem"));
7682
auto update_treeitem_shortcut = new QShortcut(QKeySequence(QObject::tr("Ctrl+U")), main_window);

qtgui/exe/src/DmsMainWindow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,18 @@ void MainWindow::expandRecursiveFromCurrentItem() {
18541854
m_treeview->expandRecursiveFromCurrentItem();
18551855
}
18561856

1857+
void MainWindow::findTreeItem() {
1858+
if (!m_treeview->find_window)
1859+
{
1860+
m_treeview->find_window = new FindTextWindow(m_treeview);
1861+
}
1862+
1863+
m_treeview->find_window->setWindowTitle("Find in configured TreeItems");
1864+
m_treeview->find_window->setSearchMode(true); // Set to TreeView mode
1865+
m_treeview->find_window->show();
1866+
m_treeview->find_window->find_text->setFocus();
1867+
}
1868+
18571869
void MainWindow::createDetailPagesDock() {
18581870
m_detailpages_dock = new QDockWidget(QObject::tr("DetailPages"), this);
18591871
m_detailpages_dock->setTitleBarWidget(new QWidget(m_detailpages_dock));

qtgui/exe/src/DmsMainWindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public slots:
215215
void debugReports();
216216
void expandActiveNode(bool doExpand);
217217
void expandRecursiveFromCurrentItem();
218+
void findTreeItem();
218219

219220
public slots:
220221
void fileOpen();
@@ -284,7 +285,7 @@ public slots:
284285

285286
// shared actions
286287
std::unique_ptr<QAction> m_export_primary_data_action
287-
, m_step_to_failreason_action, m_go_to_causa_prima_action, m_edit_config_source_action
288+
, m_step_to_failreason_action, m_go_to_causa_prima_action, m_edit_config_source_action, m_find_treeitem_action
288289
, m_update_treeitem_action, m_update_subtree_action, m_invalidate_action
289290
, m_defaultview_action, m_tableview_action, m_mapview_action, m_statistics_action
290291
// , m_histogramview_action
@@ -324,6 +325,7 @@ public slots:
324325
QPointer<DmsExportWindow> m_export_window;
325326
QPointer<DmsErrorWindow> m_error_window;
326327
QPointer<DmsFileChangedWindow> m_file_changed_window;
328+
QPointer<class FindTextWindow> m_find_treeitem_window;
327329

328330
using processing_record = std::tuple<std::time_t, std::time_t, SharedStr>;
329331
//QList<QWidgetAction*> m_recent_files_actions;

qtgui/exe/src/DmsTreeView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DmsTreeView : public QTreeView
9393
void setDmsStyleSheet(bool connecting_lines = true);
9494

9595
int m_default_size = 0;
96+
class FindTextWindow* find_window = nullptr;
9697

9798
public slots:
9899
void onDoubleClick(const QModelIndex& index);

qtgui/exe/src/UpdatableBrowser.cpp

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include <QLayout>
55
#include <qfontdatabase.h>
66

7+
#include "TicInterface.h"
8+
9+
// Forward declaration of TreeItem_FindItem from TreeItem.cpp
10+
TIC_CALL SharedTreeItem TreeItem_FindItem(const TreeItem* searchLoc, TokenID id);
11+
712
FindTextWindow::FindTextWindow(QWidget* parent)
813
: QWidget(parent)
914
{
@@ -16,6 +21,7 @@ FindTextWindow::FindTextWindow(QWidget* parent)
1621
match_case = new QCheckBox("Match case", this);
1722
previous = new QPushButton("Previous", this);
1823
next = new QPushButton("Next", this);
24+
1925
QWidget* spacer = new QWidget(this);
2026
spacer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
2127
spacer->setFocusPolicy(Qt::FocusPolicy::NoFocus);
@@ -37,6 +43,68 @@ FindTextWindow::FindTextWindow(QWidget* parent)
3743
setLayout(layout);
3844
}
3945

46+
void FindTextWindow::findInTreeView()
47+
{
48+
auto search_text = find_text->text();
49+
if (search_text.isEmpty())
50+
{
51+
result_info->setText("Please enter search text");
52+
return;
53+
}
54+
55+
auto main_window = MainWindow::TheOne();
56+
if (!main_window)
57+
{
58+
result_info->setText("Main window not available");
59+
return;
60+
}
61+
62+
auto current_item = main_window->getCurrentTreeItem();
63+
if (!current_item)
64+
{
65+
result_info->setText("No current item");
66+
return;
67+
}
68+
69+
try {
70+
TokenID search_token = GetTokenID_mt(search_text.toUtf8().constData());
71+
auto found_item = TreeItem_FindItem(current_item, search_token);
72+
73+
if (found_item)
74+
{
75+
main_window->setCurrentTreeItem(const_cast<TreeItem*>(found_item.get()));
76+
result_info->setText(QString("Found: %1").arg(found_item->GetFullName().c_str()));
77+
}
78+
else
79+
{
80+
result_info->setText("Item not found");
81+
}
82+
}
83+
catch (...)
84+
{
85+
result_info->setText("Error during search");
86+
}
87+
}
88+
89+
void FindTextWindow::setSearchMode(bool treeViewMode)
90+
{
91+
m_treeViewMode = treeViewMode;
92+
if (treeViewMode)
93+
{
94+
match_whole_word->setChecked(false);
95+
match_case->setChecked(false);
96+
match_whole_word->setEnabled(false);
97+
match_case->setEnabled(false);
98+
previous->setEnabled(false);
99+
}
100+
else
101+
{
102+
match_whole_word->setEnabled(true);
103+
match_case->setEnabled(true);
104+
previous->setEnabled(true);
105+
}
106+
}
107+
40108
void FindTextWindow::findInQTextBrowser(bool backwards)
41109
{
42110
auto* updatable_text_browser = dynamic_cast<QTextBrowser*>(parent());
@@ -56,16 +124,23 @@ void FindTextWindow::findInText(bool backwards)
56124
{
57125
if (find_text->text().isEmpty())
58126
return;
59-
60-
auto* current_parent = parent();
61-
auto* updatable_text_browser = dynamic_cast<QTextBrowser*>(current_parent);
62-
MG_CHECK(updatable_text_browser);
63-
findInQTextBrowser(backwards);
127+
128+
if (m_treeViewMode)
129+
{
130+
findInTreeView();
131+
}
132+
else
133+
{
134+
auto* current_parent = parent();
135+
auto* updatable_text_browser = dynamic_cast<QTextBrowser*>(current_parent);
136+
MG_CHECK(updatable_text_browser);
137+
findInQTextBrowser(backwards);
138+
}
64139
}
65140

66141
void FindTextWindow::nextClicked(bool checked)
67142
{
68-
findInText();
143+
findInText(false);
69144
}
70145

71146
void FindTextWindow::previousClicked(bool checked)

qtgui/exe/src/UpdatableBrowser.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,30 @@
2828

2929
class FindTextWindow : public QWidget
3030
{
31+
3132
public:
3233
FindTextWindow(QWidget* parent);
3334
void findInText(bool backwards = false);
35+
void setSearchMode(bool treeViewMode);
3436

3537
public slots:
3638
void nextClicked(bool checked = false);
3739
void previousClicked(bool checked = false);
40+
void onSourceGroupChanged(QAbstractButton* button, bool checked);
3841

3942
void findInQTextBrowser(bool backwards = false);
43+
void findInTreeView();
4044

4145
QLineEdit* find_text = nullptr;
46+
4247
QCheckBox* match_whole_word = nullptr;
4348
QCheckBox* match_case = nullptr;
4449
QPushButton* previous = nullptr;
4550
QPushButton* next = nullptr;
4651
QLabel* result_info = nullptr;
52+
53+
private:
54+
bool m_treeViewMode = false;
4755
};
4856

4957
struct QUpdatableWebBrowser : QTextBrowser, MsgGenerator

tic/dll/src/TreeItem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4611,7 +4611,7 @@ auto TreeItem_FindItem_impl(template_set& visitedSet, const TreeItem* searchLoc,
46114611
return {};
46124612
}
46134613

4614-
auto TreeItem_FindItem(const TreeItem* searchLoc, TokenID id) -> SharedTreeItem
4614+
TIC_CALL auto TreeItem_FindItem(const TreeItem* searchLoc, TokenID id) -> SharedTreeItem
46154615
{
46164616
if (!searchLoc)
46174617
return {};

0 commit comments

Comments
 (0)