mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-20 20:22:09 +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:
@@ -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