From 4b6f917f9afc0f0be007cd9e4b01cd52727532fb Mon Sep 17 00:00:00 2001 From: Peter Albrecht <albrecpe@gmail.com> Date: Thu, 11 Jan 2024 17:01:47 +0100 Subject: [PATCH] Added static resizing of tree widget columns --- .../skill_details/SkillDetailsTreeWidget.cpp | 27 +++++++++++++++---- .../skill_details/SkillDetailsTreeWidget.h | 5 ++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp index 4cf1ffffa..184aec420 100644 --- a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp +++ b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp @@ -38,7 +38,7 @@ namespace armarx::skills::gui // check the parameters: did they change? if (shownSkill.has_value()) { - auto remDesc = shownSkill.value().skillDescr; + auto remDesc = shownSkill.value().descr; if (descr.rootProfileDefaults != remDesc.rootProfileDefaults) { // TODO: ask the user if they want to reset to defaults @@ -62,10 +62,7 @@ namespace armarx::skills::gui this->expandAll(); - for (int i = 0; i < columnCount(); ++i) - { - this->resizeColumnToContents(i); - } + resizeContents(); // update the ShownSkill shownSkill = {skillId, descr}; @@ -119,6 +116,25 @@ namespace armarx::skills::gui setColumnHidden(3, true); } + /** + * Problem: columns 0 and 1 have arbitrary size; so we want to limit their size, to make sure + * everything is visible without scrolling. Column 2 is limited by design, as it only contains + * type information. + */ + void + SkillDetailsTreeWidget::resizeContents() + { + // take remainder of width (which we want to assign to dynamic columns) + const int widthRemainder = this->width() - typeWidth; + + // we want to assign half of it to each dynamic column + const int dynamicColumnSize = widthRemainder / 2; + + // set width... + this->setColumnWidth(0, dynamicColumnSize); + this->setColumnWidth(1, dynamicColumnSize); + } + aron::data::DictPtr SkillDetailsTreeWidget::getConfigAsAron() { @@ -147,6 +163,7 @@ namespace armarx::skills::gui void SkillDetailsTreeWidget::pasteCurrentConfig() { + QClipboard* clipboard = QApplication::clipboard(); std::string s = clipboard->text().toStdString(); nlohmann::json json = nlohmann::json::parse(s); diff --git a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h index d10855dbc..bd3dd78f6 100644 --- a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h +++ b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h @@ -39,8 +39,13 @@ namespace armarx::skills::gui std::optional<ShownSkill> shownSkill; + // The size, which we assume the last column to be. + // If the last column has too little space, increase this value. + const int typeWidth = 200; + AronTreeWidgetControllerPtr aronTreeWidgetController = nullptr; void setupUi(); + void resizeContents(); }; } // namespace armarx::skills::gui -- GitLab