Skip to content

Commit 3edc40d

Browse files
committed
QtCommon v4.3.0
1 parent 824e7a7 commit 3edc40d

14 files changed

+1585
-9
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project(QtCommon)
33

44
# Define version information
55
set(QTCOMMON_MAJOR_VERSION 4)
6-
set(QTCOMMON_MINOR_VERSION 2)
6+
set(QTCOMMON_MINOR_VERSION 3)
77
if (NOT QTCOMMON_PATCH_NUMBER)
88
set(QTCOMMON_PATCH_NUMBER 0)
99
endif ()

source/qt_common/custom_widgets/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ file (GLOB CPP_INC
2424
"graphics_scene.h"
2525
"graphics_view.h"
2626
"icon_button.h"
27+
"include_directories_view.h"
2728
"list_widget.h"
2829
"message_overlay.h"
2930
"message_overlay_container.h"
3031
"navigation_bar.h"
3132
"navigation_list_widget.h"
3233
"navigation_list_view.h"
3334
"navigation_list_model.h"
35+
"ordered_list_dialog.h"
3436
"quick_link_button_widget.h"
3537
"recent_trace_mini_widget.h"
3638
"recent_trace_widget.h"
@@ -56,6 +58,7 @@ file (GLOB CPP_INC
5658
"tab_widget.h"
5759
"text_search_widget.h"
5860
"timeline_view.h"
61+
"tooltip_widget.h"
5962
)
6063

6164
# Add any .ui files
@@ -64,6 +67,7 @@ file (GLOB UI_SRC
6467
"driver_overrides_notification_config_widget.ui"
6568
"driver_overrides_tree_widget.ui"
6669
"message_overlay.ui"
70+
"ordered_list_view_dialog.ui"
6771
)
6872

6973
# Add all source files found within this directory.
@@ -86,13 +90,15 @@ file (GLOB CPP_SRC
8690
"graphics_scene.cpp"
8791
"graphics_view.cpp"
8892
"icon_button.cpp"
93+
"include_directories_view.cpp"
8994
"list_widget.cpp"
9095
"message_overlay.cpp"
9196
"message_overlay_container.cpp"
9297
"navigation_bar.cpp"
9398
"navigation_list_widget.cpp"
9499
"navigation_list_view.cpp"
95100
"navigation_list_model.cpp"
101+
"ordered_list_dialog.cpp"
96102
"quick_link_button_widget.cpp"
97103
"recent_trace_mini_widget.cpp"
98104
"recent_trace_widget.cpp"
@@ -118,6 +124,7 @@ file (GLOB CPP_SRC
118124
"tree_view.cpp"
119125
"text_search_widget.cpp"
120126
"timeline_view.cpp"
127+
"tooltip_widget.cpp"
121128
)
122129

123130
# Pick up the source files that are relevant to the platform

source/qt_common/custom_widgets/arrow_icon_combo_box.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,10 @@ void ArrowIconComboBox::paintEvent(QPaintEvent* event)
906906
painter.setRenderHint(QPainter::Antialiasing);
907907
painter.save();
908908

909+
// Draw the background.
910+
const QColor& color = palette().color(QPalette::Base);
911+
painter.fillRect(rect(), color);
912+
909913
// Set properties for the lines
910914
QPen pen;
911915

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
//=============================================================================
2+
/// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
3+
/// @author AMD Developer Tools Team
4+
/// @file
5+
/// @brief Implementation for our include directories view dialog
6+
//=============================================================================
7+
8+
#include "include_directories_view.h"
9+
10+
#include <algorithm>
11+
#include <cassert>
12+
#include <sstream>
13+
14+
#include <QFileDialog>
15+
#include <QMessageBox>
16+
#include <QPushButton>
17+
#include <QVBoxLayout>
18+
19+
#include "common_definitions.h"
20+
21+
static const char* kStrIncludeDirDialogBrowseButton = "&Browse..."; ///< Select include directories browse button string.
22+
static const char* kStrIncludeDirDialogDirDoesNotExist = "This directory does not exist."; ///< Select include directory does not exist message string.
23+
static const char* kStrIncludeDirDialogDirAlreadySelected = "This directory is already selected."; ///< Select include directory already set message string.
24+
static const char* kStrIncludeDirDialogSelectDirTitle = "Select a directory"; ///< Select include directories file dialog title string.
25+
26+
IncludeDirectoriesView::IncludeDirectoriesView(const QString& delimiter, const QString& window_title, const QIcon& window_icon, QWidget* parent)
27+
: OrderedListDialog(delimiter, window_icon, parent)
28+
{
29+
// Initialize the browse button that gets inserted into the view.
30+
InitializeBrowseButton();
31+
32+
// Set the window title.
33+
setWindowTitle(window_title);
34+
35+
// Connect the signals.
36+
ConnectSignals();
37+
38+
// Set the mouse cursor to the pointing hand cursor for various widgets.
39+
SetCursor();
40+
41+
// Set the button fonts.
42+
SetButtonFonts();
43+
44+
// Update various buttons.
45+
UpdateButtons();
46+
}
47+
48+
void IncludeDirectoriesView::ConnectSignals()
49+
{
50+
assert(browse_push_button_ != nullptr);
51+
52+
// Browse new include directory button.
53+
[[maybe_unused]] bool is_connected =
54+
connect(browse_push_button_, &QPushButton::clicked, this, &IncludeDirectoriesView::HandleIncludeFileLocationBrowseButtonClick);
55+
assert(is_connected);
56+
}
57+
58+
void IncludeDirectoriesView::InitializeBrowseButton()
59+
{
60+
// Create a new button to browse for new directories.
61+
browse_push_button_ = new QPushButton(this);
62+
browse_push_button_->setText(kStrIncludeDirDialogBrowseButton);
63+
64+
assert(browse_push_button_ != nullptr);
65+
if (browse_push_button_ != nullptr)
66+
{
67+
// This index specifies where the browse button will get inserted in the vertical layout of buttons in the dialog.
68+
static const int kBrowseButtonInsertionIndex = 2;
69+
70+
// Add the new browse button to the view.
71+
QVBoxLayout* vertical_buttons_layout = GetVerticalPushButtonsLayout();
72+
assert(vertical_buttons_layout != nullptr);
73+
if (vertical_buttons_layout != nullptr)
74+
{
75+
vertical_buttons_layout->insertWidget(kBrowseButtonInsertionIndex, browse_push_button_);
76+
}
77+
}
78+
}
79+
80+
void IncludeDirectoriesView::SetCursor()
81+
{
82+
assert(browse_push_button_ != nullptr);
83+
if (browse_push_button_ != nullptr)
84+
{
85+
// Set the cursor to pointing hand cursor on the Browse button.
86+
browse_push_button_->setCursor(Qt::PointingHandCursor);
87+
}
88+
}
89+
90+
void IncludeDirectoriesView::SetButtonFonts()
91+
{
92+
// Create a font based on other QPushButtons in within the view.
93+
QFont font = GetDeletePushButton()->font();
94+
font.setPointSize(kButtonFontPointSize);
95+
96+
assert(browse_push_button_ != nullptr);
97+
if (browse_push_button_ != nullptr)
98+
{
99+
// Update font size for all the buttons.
100+
browse_push_button_->setFont(font);
101+
}
102+
}
103+
104+
void IncludeDirectoriesView::SetDefaultFolderPath(std::string default_folder_path)
105+
{
106+
default_folder_path_ = default_folder_path;
107+
}
108+
109+
void IncludeDirectoriesView::HandleIncludeFileLocationBrowseButtonClick(bool /* checked */)
110+
{
111+
// Create a file chooser dialog.
112+
QFileDialog file_dialog;
113+
114+
// Get the last entry from the directories list and open the dialog there.
115+
std::string latest_path = default_folder_path_;
116+
// If the user has an item selected, use that as starting path.
117+
// Otherwise use the last item in the list since it is probably most recent.
118+
QListWidgetItem* item = GetItemsListWidget()->currentItem();
119+
if (item != nullptr && !item->text().isEmpty() && QDir(item->text()).exists())
120+
{
121+
latest_path = item->text().toStdString();
122+
}
123+
else if (items_list_.size() > 0)
124+
{
125+
latest_path = items_list_.at(items_list_.size() - 1).toStdString();
126+
}
127+
128+
bool should_show_find_directory_dialog = true;
129+
130+
while (should_show_find_directory_dialog)
131+
{
132+
QString selected_directory =
133+
QFileDialog::getExistingDirectory(this, tr(kStrIncludeDirDialogSelectDirTitle), latest_path.c_str(), QFileDialog::ShowDirsOnly);
134+
135+
// If the user did not select an entry, don't update anything, just exit the loop.
136+
if (selected_directory.isEmpty())
137+
{
138+
should_show_find_directory_dialog = false;
139+
}
140+
else
141+
{
142+
// If not a duplicate selection, update the list widget.
143+
if (!items_list_.contains(selected_directory))
144+
{
145+
item = GetItemsListWidget()->currentItem();
146+
if (item == nullptr)
147+
{
148+
// There was no selected item,
149+
// so make sure there is a final entry that is empty, and edit that.
150+
if (GetItemsListWidget()->count() > 0)
151+
{
152+
item = GetItemsListWidget()->item(GetItemsListWidget()->count() - 1);
153+
}
154+
155+
if (item == nullptr || !item->text().isEmpty())
156+
{
157+
// Add an empty row to the dialog
158+
InsertBlankItem();
159+
assert(GetItemsListWidget()->count() > 0);
160+
161+
// Use the empty row for the new item
162+
item = GetItemsListWidget()->item(GetItemsListWidget()->count() - 1);
163+
}
164+
}
165+
166+
assert(item != nullptr);
167+
item->setText(selected_directory);
168+
169+
// If the last item in the UI is no longer empty, add another item.
170+
item = GetItemsListWidget()->item(GetItemsListWidget()->count() - 1);
171+
if (item == nullptr || !item->text().isEmpty())
172+
{
173+
// Add an empty row to the dialog
174+
InsertBlankItem();
175+
}
176+
177+
// Don't show the find directory dialog again.
178+
should_show_find_directory_dialog = false;
179+
}
180+
else
181+
{
182+
// Display an error message when a duplicate directory is selected.
183+
QMessageBox::critical(this, "Error", kStrIncludeDirDialogDirAlreadySelected);
184+
185+
// Make the user try again.
186+
should_show_find_directory_dialog = true;
187+
}
188+
}
189+
}
190+
191+
// Update move buttons.
192+
UpdateButtons();
193+
}
194+
195+
void IncludeDirectoriesView::OnListItemChanged(QListWidgetItem* item)
196+
{
197+
// Block signals from the list widget.
198+
GetItemsListWidget()->blockSignals(true);
199+
200+
editing_invalid_entry_ = false;
201+
202+
// Process the newly-entered data.
203+
if (item != nullptr)
204+
{
205+
QString new_directory = item->text();
206+
207+
bool directory_exists = QDir(new_directory).exists();
208+
bool directory_duplicate = items_list_.contains(new_directory);
209+
bool directory_value_empty = new_directory.isEmpty();
210+
211+
int item_row = GetItemsListWidget()->row(item);
212+
213+
if (directory_value_empty && item_row != GetItemsListWidget()->count() - 1)
214+
{
215+
// The user has emptied out the entry, so delete it.
216+
// Simulate a click on the delete button to remove the entry from the UI.
217+
GetDeletePushButton()->click();
218+
}
219+
else
220+
{
221+
// If the new directory exists, and it is not a duplicate entry, update local data.
222+
if (!directory_exists || directory_duplicate)
223+
{
224+
// Display an error message box.
225+
if (!directory_exists)
226+
{
227+
QMessageBox::critical(this, "Error", kStrIncludeDirDialogDirDoesNotExist);
228+
}
229+
else if (directory_duplicate)
230+
{
231+
QMessageBox::critical(this, "Error", kStrIncludeDirDialogDirAlreadySelected);
232+
}
233+
234+
editing_invalid_entry_ = true;
235+
}
236+
237+
// Update local data.
238+
if (item_row < items_list_.count())
239+
{
240+
items_list_[item_row] = new_directory;
241+
}
242+
else
243+
{
244+
items_list_.append(new_directory);
245+
}
246+
}
247+
248+
// Update tool tips.
249+
UpdateToolTips();
250+
251+
// Unblock signals from the list widget.
252+
GetItemsListWidget()->blockSignals(false);
253+
254+
// Update buttons.
255+
UpdateButtons();
256+
}
257+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//=============================================================================
2+
/// Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
3+
/// @author AMD Developer Tools Team
4+
/// @file
5+
/// @brief Header for our include directories view dialog
6+
//=============================================================================
7+
8+
#ifndef QTCOMMON_CUSTOM_WIDGETS_INCLUDE_DIRECTORIES_VIEW_H_
9+
#define QTCOMMON_CUSTOM_WIDGETS_INCLUDE_DIRECTORIES_VIEW_H_
10+
11+
#include "ordered_list_dialog.h"
12+
13+
/// @brief Class that implements the include directories view
14+
class IncludeDirectoriesView : public OrderedListDialog
15+
{
16+
Q_OBJECT
17+
18+
public:
19+
/// @brief Constructor for IncludeDirectoriesView.
20+
/// @param [in] delimiter The delimiter used to split the ordered list managed by this class.
21+
/// @param [in] window_title The window title for this dialog.
22+
/// @param [in] window_icon The window icon for this dialog.
23+
/// @param [in] parent The parent widget.
24+
IncludeDirectoriesView(const QString& delimiter, const QString& window_title, const QIcon& window_icon = {}, QWidget* parent = nullptr);
25+
26+
/// @brief Destructor.
27+
virtual ~IncludeDirectoriesView() = default;
28+
29+
/// @brief Set a default folder path to be used by this dialog.
30+
/// @param [in] entries The default folder path as input.
31+
void SetDefaultFolderPath(std::string default_folder_path);
32+
33+
private slots:
34+
/// @brief Handler when the include file browse button is clicked.
35+
void HandleIncludeFileLocationBrowseButtonClick(bool /* checked */);
36+
37+
protected:
38+
/// @brief An overridden virtual responsible for determining if an edited list item is valid.
39+
/// @param [in] item The list widget item that changed.
40+
virtual void OnListItemChanged(QListWidgetItem* item) override;
41+
42+
private:
43+
/// @brief Connect the signals.
44+
void ConnectSignals();
45+
46+
/// @brief Initialize the view and add a "Browse" button to browse for new directories to add.
47+
void InitializeBrowseButton();
48+
49+
/// @brief Set the cursor to pointing hand cursor for various widgets.
50+
void SetCursor();
51+
52+
/// @brief Set the button fonts.
53+
void SetButtonFonts();
54+
55+
QPushButton* browse_push_button_ = nullptr; ///< A "Browse" QPushButton used to browse new directories to add.
56+
std::string default_folder_path_ = "./"; ///< The default folder path, to be set by the client of this dialog.
57+
};
58+
#endif // QTCOMMON_CUSTOM_WIDGETS_INCLUDE_DIRECTORIES_VIEW_H_

0 commit comments

Comments
 (0)