mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-06 07:51:47 +00:00
Simplify Models panel and dialog layout
Models panel: replace the manual resizeEvent column-sizing hack with QHeaderView Stretch/Fixed modes, re-applied via sectionCountChanged so they survive the model rebuilds that QHeaderView resets them on. Dialog: only wrap the body in a QScrollArea when scrollable, mirroring Panel. The scroll area caps its sizeHint at 36x24 cells, which turned wide fixed-size dialog content into spurious scrollbars. Add Model dialog: reserve a stable, font-metrics-measured height for the hover description so longer text never reflows the buttons; regroup the buttons into LOCAL / CLOUD / TOOLS. Buttons: move the trailing-separator decision out of makeButtonGroup into a new addButtonGroups row builder, so the last group in a row never draws a dangling divider. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -232,9 +232,11 @@ QWidget* MainWindow::buildHomeRibbonPage() {
|
||||
dialog.exec();
|
||||
});
|
||||
|
||||
row->addWidget(components::buttons::makeButtonGroup("PROJECT", {new_project, open_project, open_cloud, open_recent, save_project}, this));
|
||||
row->addWidget(components::buttons::makeButtonGroup("MODELS", {add_model, sync_from_cloud}, this));
|
||||
row->addWidget(components::buttons::makeButtonGroup("SETTINGS", {settings_button}, this));
|
||||
components::buttons::addButtonGroups(row, {
|
||||
components::buttons::makeButtonGroup("PROJECT", {new_project, open_project, open_cloud, open_recent, save_project}, this),
|
||||
components::buttons::makeButtonGroup("MODELS", {add_model, sync_from_cloud}, this),
|
||||
components::buttons::makeButtonGroup("SETTINGS", {settings_button}, this),
|
||||
});
|
||||
row->addStretch(1);
|
||||
return page;
|
||||
}
|
||||
@@ -296,9 +298,11 @@ QWidget* MainWindow::buildNavigateRibbonPage() {
|
||||
modules::viewport::commands::toggleSection(*session_state_, *viewport_widget_->viewport());
|
||||
});
|
||||
|
||||
row->addWidget(components::buttons::makeButtonGroup("CAMERA", {set_home, go_home, view_all, view_selected}, this));
|
||||
row->addWidget(components::buttons::makeButtonGroup("ORIENTATION", {plan_view, front_view, side_view, align_object, projection_button}, this));
|
||||
row->addWidget(components::buttons::makeButtonGroup("MODE", {fly_mode, section_mode}, this));
|
||||
components::buttons::addButtonGroups(row, {
|
||||
components::buttons::makeButtonGroup("CAMERA", {set_home, go_home, view_all, view_selected}, this),
|
||||
components::buttons::makeButtonGroup("ORIENTATION", {plan_view, front_view, side_view, align_object, projection_button}, this),
|
||||
components::buttons::makeButtonGroup("MODE", {fly_mode, section_mode}, this),
|
||||
});
|
||||
row->addStretch(1);
|
||||
return page;
|
||||
}
|
||||
@@ -340,8 +344,10 @@ QWidget* MainWindow::buildInspectRibbonPage() {
|
||||
modules::viewport::commands::toggleVolume(*viewport_widget_->viewport());
|
||||
});
|
||||
|
||||
row->addWidget(components::buttons::makeButtonGroup("SELECTION", {hide_selected, isolate_selected, show_all, invert_selection}, this));
|
||||
row->addWidget(components::buttons::makeButtonGroup("MEASURE", {distance, area, volume}, this));
|
||||
components::buttons::addButtonGroups(row, {
|
||||
components::buttons::makeButtonGroup("SELECTION", {hide_selected, isolate_selected, show_all, invert_selection}, this),
|
||||
components::buttons::makeButtonGroup("MEASURE", {distance, area, volume}, this),
|
||||
});
|
||||
row->addStretch(1);
|
||||
return page;
|
||||
}
|
||||
@@ -353,22 +359,24 @@ QWidget* MainWindow::buildPanelsRibbonPage() {
|
||||
row->setContentsMargins(2, 4, 2, 4);
|
||||
row->setSpacing(0);
|
||||
|
||||
row->addWidget(components::buttons::makeButtonGroup("DATA", {
|
||||
makePanelToggle("Models", models_panel_),
|
||||
makePanelToggle("Spatial", spatial_panel_),
|
||||
makePanelToggle("Layers", layers_panel_),
|
||||
makePanelToggle("Properties", properties_panel_)
|
||||
}, this));
|
||||
row->addWidget(components::buttons::makeButtonGroup("QUERY", {
|
||||
makePanelToggle("Views", stored_views_panel_),
|
||||
makePanelToggle("Search", search_panel_),
|
||||
makePanelToggle("Sheets", spreadsheet_panel_),
|
||||
makePanelToggle("Audit", audit_panel_)
|
||||
}, this));
|
||||
row->addWidget(components::buttons::makeButtonGroup("COLLABORATE", {
|
||||
makePanelToggle("Clash", clash_panel_),
|
||||
makePanelToggle("Issues", issues_panel_)
|
||||
}, this));
|
||||
components::buttons::addButtonGroups(row, {
|
||||
components::buttons::makeButtonGroup("DATA", {
|
||||
makePanelToggle("Models", models_panel_),
|
||||
makePanelToggle("Spatial", spatial_panel_),
|
||||
makePanelToggle("Layers", layers_panel_),
|
||||
makePanelToggle("Properties", properties_panel_)
|
||||
}, this),
|
||||
components::buttons::makeButtonGroup("QUERY", {
|
||||
makePanelToggle("Views", stored_views_panel_),
|
||||
makePanelToggle("Search", search_panel_),
|
||||
makePanelToggle("Sheets", spreadsheet_panel_),
|
||||
makePanelToggle("Audit", audit_panel_)
|
||||
}, this),
|
||||
components::buttons::makeButtonGroup("COLLABORATE", {
|
||||
makePanelToggle("Clash", clash_panel_),
|
||||
makePanelToggle("Issues", issues_panel_)
|
||||
}, this),
|
||||
});
|
||||
row->addStretch(1);
|
||||
return page;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "SvgIcon.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
@@ -47,11 +48,9 @@ QToolButton* makeButton(const QString& text,
|
||||
QWidget* makeButtonGroup(const QString& title,
|
||||
const QList<QToolButton*>& buttons,
|
||||
QWidget* parent,
|
||||
bool trailing_separator,
|
||||
int vertical_spacing) {
|
||||
auto* group = new QFrame(parent);
|
||||
group->setObjectName("ribbonGroup");
|
||||
group->setProperty("separator", trailing_separator);
|
||||
|
||||
auto* group_layout = new QVBoxLayout(group);
|
||||
group_layout->setContentsMargins(8, 6, 8, 4);
|
||||
@@ -74,4 +73,13 @@ QWidget* makeButtonGroup(const QString& title,
|
||||
return group;
|
||||
}
|
||||
|
||||
void addButtonGroups(QBoxLayout* row, const QList<QWidget*>& groups) {
|
||||
for (int i = 0; i < groups.size(); ++i) {
|
||||
// The divider belongs *between* groups; the last group never draws a
|
||||
// trailing one. The stylesheet keys off this dynamic property.
|
||||
groups[i]->setProperty("separator", i + 1 < groups.size());
|
||||
row->addWidget(groups[i]);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace bonsaiviewer::components::buttons
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <QList>
|
||||
|
||||
class QBoxLayout;
|
||||
class QToolButton;
|
||||
class QWidget;
|
||||
|
||||
@@ -35,9 +36,13 @@ QToolButton* makeButton(const QString& text,
|
||||
QWidget* makeButtonGroup(const QString& title,
|
||||
const QList<QToolButton*>& buttons,
|
||||
QWidget* parent,
|
||||
bool trailing_separator = true,
|
||||
int vertical_spacing = 4);
|
||||
|
||||
// Adds button groups to a ribbon row, drawing a vertical divider between
|
||||
// adjacent groups but never after the last one. Centralising the decision
|
||||
// here means a row can't end up with a dangling trailing separator.
|
||||
void addButtonGroups(QBoxLayout* row, const QList<QWidget*>& groups);
|
||||
|
||||
} // namespace bonsaiviewer::components::buttons
|
||||
|
||||
#endif
|
||||
|
||||
@@ -49,19 +49,27 @@ Dialog::Dialog(QWidget* parent, bool scrollable)
|
||||
style::metrics::section_body_padding);
|
||||
frame_layout->setSpacing(0);
|
||||
|
||||
auto* scroll = new QScrollArea(frame);
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setFrameShape(QFrame::NoFrame);
|
||||
|
||||
auto* scroll_body = new QWidget(scroll);
|
||||
scroll_body->setObjectName("panelScrollBody");
|
||||
body_layout_ = new QVBoxLayout(scroll_body);
|
||||
// A non-scrollable dialog must not be wrapped in a QScrollArea. The scroll
|
||||
// area caps its own sizeHint at 36x24 character cells, and dialogs size
|
||||
// themselves with QLayout::SetFixedSize — so any content wider/taller than
|
||||
// that cap is turned into scrollbars instead of growing the dialog. Only
|
||||
// use a scroll area when scrolling is actually wanted (mirrors Panel).
|
||||
auto* body = new QWidget(frame);
|
||||
body->setObjectName("panelScrollBody");
|
||||
body_layout_ = new QVBoxLayout(body);
|
||||
body_layout_->setContentsMargins(0, 0, 0, 0);
|
||||
body_layout_->setSpacing(style::metrics::section_body_padding);
|
||||
body_layout_->setAlignment(Qt::AlignTop);
|
||||
|
||||
scroll->setWidget(scroll_body);
|
||||
frame_layout->addWidget(scroll, scrollable ? 1 : 0);
|
||||
if (scrollable) {
|
||||
auto* scroll = new QScrollArea(frame);
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setFrameShape(QFrame::NoFrame);
|
||||
scroll->setWidget(body);
|
||||
frame_layout->addWidget(scroll, 1);
|
||||
} else {
|
||||
frame_layout->addWidget(body);
|
||||
}
|
||||
|
||||
auto* footer = new QWidget(frame);
|
||||
footer_layout_ = new QVBoxLayout(footer);
|
||||
|
||||
@@ -69,7 +69,9 @@ ConnectorPickerDialog::ConnectorPickerDialog(const std::vector<ConnectorManifest
|
||||
});
|
||||
buttons.push_back(button);
|
||||
}
|
||||
row->addWidget(components::buttons::makeButtonGroup("CONNECTORS", buttons, choices, true, 8));
|
||||
components::buttons::addButtonGroups(row, {
|
||||
components::buttons::makeButtonGroup("CONNECTORS", buttons, choices, 8),
|
||||
});
|
||||
choices_section->addBodyWidget(choices);
|
||||
|
||||
addBodyWidget(description_section);
|
||||
|
||||
@@ -74,13 +74,12 @@ void AddModelDialog::setupUi() {
|
||||
}
|
||||
|
||||
const QString default_description = "Choose what to add to the project";
|
||||
|
||||
auto* description_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
|
||||
auto* description = new QLabel(default_description, description_section);
|
||||
description->setProperty("textRole", "secondary");
|
||||
description->setWordWrap(true);
|
||||
description->setAlignment(Qt::AlignCenter);
|
||||
description->setMinimumWidth((90 * 4) + (components::style::metrics::padding * 3));
|
||||
description->setMinimumHeight(description->fontMetrics().lineSpacing() * 2 + 4);
|
||||
description_section->addBodyWidget(description);
|
||||
|
||||
auto* choices_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
|
||||
@@ -89,70 +88,73 @@ void AddModelDialog::setupUi() {
|
||||
row->setContentsMargins(0, 0, 0, 0);
|
||||
row->setSpacing(components::style::metrics::padding);
|
||||
|
||||
auto* add_ifc = components::buttons::makeButton("Add IFC File", ":/icons/cube.svg", choices);
|
||||
connect(add_ifc, &QToolButton::clicked, this, [this]() {
|
||||
selected_mode_ = SourceMode::IfcFile;
|
||||
accept();
|
||||
});
|
||||
add_ifc->installEventFilter(new HoverDescriptionFilter(
|
||||
description,
|
||||
"Add IFC files and load both geometry and data.",
|
||||
default_description));
|
||||
struct Choice {
|
||||
SourceMode mode;
|
||||
QString text;
|
||||
QString icon;
|
||||
QString hover;
|
||||
};
|
||||
const QList<Choice> local_choices = {
|
||||
{SourceMode::IfcFile, "Add IFC File", ":/icons/cube.svg",
|
||||
"Add IFC files and load both geometry and data."},
|
||||
{SourceMode::IfcDatabase, "Add IFC\nDatabase", ":/icons/database.svg",
|
||||
"Add IFC RDB databases for optimised performance"},
|
||||
{SourceMode::GeometryOnly, "Add Geometry", ":/icons/cube-bandage.svg",
|
||||
"Add pure geometry for fast visualisation"},
|
||||
};
|
||||
const QList<Choice> cloud_choices = {
|
||||
{SourceMode::CloudModel, "Add From\nCloud", ":/icons/cloud-square.svg",
|
||||
"Browse a cloud connector and add one or more models from there."},
|
||||
};
|
||||
const QList<Choice> tool_choices = {
|
||||
{SourceMode::ConvertToDatabase, "Convert IFC File\nto Database", ":/icons/database-restore.svg",
|
||||
"Convert IFC files to databases for smaller filesizes, reduced memory, "
|
||||
"and faster access. No data is lost."},
|
||||
{SourceMode::ExportGeometryDatabase, "Export Geometry\nDatabase", ":/icons/database-restore.svg",
|
||||
"Convert IFC files to a read-only geometry database for smaller filesizes, "
|
||||
"reduced memory, and faster access. Ideal for cloud read-only coordination "
|
||||
"workflows. Only parametric geometry editing capabilities are lost."},
|
||||
};
|
||||
|
||||
auto* add_database = components::buttons::makeButton("Add IFC\nDatabase", ":/icons/database.svg", choices);
|
||||
connect(add_database, &QToolButton::clicked, this, [this]() {
|
||||
selected_mode_ = SourceMode::IfcDatabase;
|
||||
accept();
|
||||
});
|
||||
add_database->installEventFilter(new HoverDescriptionFilter(
|
||||
description,
|
||||
"Add IFC RDB databases for optimised performance",
|
||||
default_description));
|
||||
QStringList descriptions = {default_description};
|
||||
auto build_group = [&](const QString& title, const QList<Choice>& group_choices) {
|
||||
QList<QToolButton*> buttons;
|
||||
for (const Choice& choice : group_choices) {
|
||||
auto* button = components::buttons::makeButton(choice.text, choice.icon, choices);
|
||||
const SourceMode mode = choice.mode;
|
||||
connect(button, &QToolButton::clicked, this, [this, mode]() {
|
||||
selected_mode_ = mode;
|
||||
accept();
|
||||
});
|
||||
button->installEventFilter(
|
||||
new HoverDescriptionFilter(description, choice.hover, default_description));
|
||||
descriptions << choice.hover;
|
||||
buttons << button;
|
||||
}
|
||||
return components::buttons::makeButtonGroup(title, buttons, choices, 8);
|
||||
};
|
||||
|
||||
auto* add_geometry = components::buttons::makeButton("Add Geometry", ":/icons/cube-bandage.svg", choices);
|
||||
connect(add_geometry, &QToolButton::clicked, this, [this]() {
|
||||
selected_mode_ = SourceMode::GeometryOnly;
|
||||
accept();
|
||||
components::buttons::addButtonGroups(row, {
|
||||
build_group("LOCAL", local_choices),
|
||||
build_group("CLOUD", cloud_choices),
|
||||
build_group("TOOLS", tool_choices),
|
||||
});
|
||||
add_geometry->installEventFilter(new HoverDescriptionFilter(
|
||||
description,
|
||||
"Add pure geometry for fast visualisation",
|
||||
default_description));
|
||||
|
||||
auto* add_cloud = components::buttons::makeButton("Add From\nCloud", ":/icons/cloud-square.svg", choices);
|
||||
connect(add_cloud, &QToolButton::clicked, this, [this]() {
|
||||
selected_mode_ = SourceMode::CloudModel;
|
||||
accept();
|
||||
});
|
||||
add_cloud->installEventFilter(new HoverDescriptionFilter(
|
||||
description,
|
||||
"Browse a cloud connector and add one or more models from there.",
|
||||
default_description));
|
||||
|
||||
auto* convert_database = components::buttons::makeButton("Convert IFC File\nto Database", ":/icons/database-restore.svg", choices);
|
||||
connect(convert_database, &QToolButton::clicked, this, [this]() {
|
||||
selected_mode_ = SourceMode::ConvertToDatabase;
|
||||
accept();
|
||||
});
|
||||
convert_database->installEventFilter(new HoverDescriptionFilter(
|
||||
description,
|
||||
"Convert IFC files to databases for smaller filesizes, reduced memory, and faster access. No data is lost.",
|
||||
default_description));
|
||||
|
||||
auto* export_geometry_database = components::buttons::makeButton("Export Geometry\nDatabase", ":/icons/database-restore.svg", choices);
|
||||
connect(export_geometry_database, &QToolButton::clicked, this, [this]() {
|
||||
selected_mode_ = SourceMode::ExportGeometryDatabase;
|
||||
accept();
|
||||
});
|
||||
export_geometry_database->installEventFilter(new HoverDescriptionFilter(
|
||||
description,
|
||||
"Convert IFC files to a read-only geometry database for smaller filesizes, reduced memory, and faster access. Ideal for cloud read-only coordination workflows. Only parametric geometry editing capabilities are lost.",
|
||||
default_description));
|
||||
|
||||
row->addWidget(components::buttons::makeButtonGroup("ADD", {add_ifc, add_database, add_geometry, add_cloud}, choices, true, 8));
|
||||
row->addWidget(components::buttons::makeButtonGroup("TOOLS", {convert_database, export_geometry_database}, choices, false, 8));
|
||||
choices_section->addBodyWidget(choices);
|
||||
|
||||
// Hovering a button swaps in a longer description; with a free-growing
|
||||
// label that reflow shoves the buttons below it downward. Lock the label
|
||||
// to the tallest string it will ever show. The label is laid out at the
|
||||
// choices' width (both sit in Section bodies with identical margins), so
|
||||
// measure every string at that width and keep the largest result.
|
||||
const int label_width = choices->sizeHint().width();
|
||||
int reserved_height = 0;
|
||||
for (const QString& text : descriptions) {
|
||||
description->setText(text);
|
||||
reserved_height = qMax(reserved_height, description->heightForWidth(label_width));
|
||||
}
|
||||
description->setText(default_description);
|
||||
description->setFixedHeight(reserved_height);
|
||||
|
||||
addBodyWidget(description_section);
|
||||
addBodyWidget(choices_section);
|
||||
}
|
||||
|
||||
@@ -89,15 +89,6 @@ public:
|
||||
: QTreeView(parent), session_state_(session_state) {}
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent* event) override {
|
||||
QTreeView::resizeEvent(event);
|
||||
if (model() && model()->columnCount() >= 2) {
|
||||
const int vw = viewport()->width();
|
||||
setColumnWidth(0, std::max(40, vw - kVisibilityColumnWidth));
|
||||
setColumnWidth(1, kVisibilityColumnWidth);
|
||||
}
|
||||
}
|
||||
|
||||
void startDrag(Qt::DropActions actions) override {
|
||||
const QModelIndexList selection = selectionModel()->selectedRows(0);
|
||||
if (selection.isEmpty()) return;
|
||||
@@ -382,14 +373,25 @@ ModelsPanel::ModelsPanel(bonsaiviewer::SessionState* session_state,
|
||||
void ModelsPanel::setModel(FederationItemModel* model) {
|
||||
model_ = model;
|
||||
tree_->setModel(model);
|
||||
// Columns are sized by ModelsTreeView::resizeEvent — header is hidden so
|
||||
// there's no user-facing resize affordance, and Stretch mode on
|
||||
// non-last sections proved unreliable here. Manual sizing is simpler.
|
||||
tree_->header()->setMinimumSectionSize(16);
|
||||
tree_->header()->setStretchLastSection(false);
|
||||
tree_->setColumnWidth(0, std::max(40, tree_->viewport()->width() - kVisibilityColumnWidth));
|
||||
tree_->setColumnWidth(1, kVisibilityColumnWidth);
|
||||
// QHeaderView resets per-section resize modes to Interactive whenever the
|
||||
// column set is rebuilt — which FederationItemModel::rebuildAll() does on
|
||||
// project open / theme change (clear() + setColumnCount()). Re-apply the
|
||||
// layout every time the columns reappear.
|
||||
connect(tree_->header(), &QHeaderView::sectionCountChanged,
|
||||
this, [this]() { applyColumnLayout(); });
|
||||
applyColumnLayout();
|
||||
tree_->expandAll();
|
||||
}
|
||||
|
||||
void ModelsPanel::applyColumnLayout() {
|
||||
// Column 0 (name) stretches to fill; column 1 (visibility icon) is fixed.
|
||||
QHeaderView* header = tree_->header();
|
||||
if (header->count() < 2) return;
|
||||
header->setStretchLastSection(false);
|
||||
header->setMinimumSectionSize(kVisibilityColumnWidth);
|
||||
header->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
header->setSectionResizeMode(1, QHeaderView::Fixed);
|
||||
header->resizeSection(1, kVisibilityColumnWidth);
|
||||
}
|
||||
|
||||
} // namespace bonsaiviewer::modules::models
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
void setModel(FederationItemModel* model);
|
||||
|
||||
private:
|
||||
void applyColumnLayout();
|
||||
|
||||
bonsaiviewer::SessionState* session_state_ = nullptr;
|
||||
ViewportWindow* viewport_ = nullptr;
|
||||
QTreeView* tree_ = nullptr;
|
||||
|
||||
@@ -135,10 +135,10 @@ void SaveProjectDialog::setupUi(bool has_manifest) {
|
||||
"Pick a connector and push this project to a fresh cloud location.",
|
||||
default_description));
|
||||
|
||||
row->addWidget(components::buttons::makeButtonGroup(
|
||||
"LOCAL", {save_local, save_as_local}, choices, true, 8));
|
||||
row->addWidget(components::buttons::makeButtonGroup(
|
||||
"CLOUD", {save_cloud, save_as_cloud}, choices, false, 8));
|
||||
components::buttons::addButtonGroups(row, {
|
||||
components::buttons::makeButtonGroup("LOCAL", {save_local, save_as_local}, choices, 8),
|
||||
components::buttons::makeButtonGroup("CLOUD", {save_cloud, save_as_cloud}, choices, 8),
|
||||
});
|
||||
choices_section->addBodyWidget(choices);
|
||||
|
||||
addBodyWidget(description_section);
|
||||
|
||||
Reference in New Issue
Block a user