Gui: Improve layout expression dialog for varsets

According to #17075
This commit is contained in:
Pieter Hijma
2025-07-20 09:51:05 +02:00
parent 146c84cf1e
commit acea58f85f
3 changed files with 89 additions and 123 deletions

View File

@@ -36,6 +36,7 @@
#include <App/DocumentObject.h>
#include <App/ExpressionParser.h>
#include <App/VarSet.h>
#include <Base/Console.h>
#include <Base/Tools.h>
#include "Dialogs/DlgExpressionInput.h"
@@ -50,6 +51,9 @@
using namespace App;
using namespace Gui::Dialog;
FC_LOG_LEVEL_INIT("DlgExpressionInput", true, true)
bool DlgExpressionInput::varSetsVisible = false;
DlgExpressionInput::DlgExpressionInput(const App::ObjectIdentifier & _path,
@@ -204,9 +208,6 @@ bool DlgExpressionInput::typeOkForVarSet()
void DlgExpressionInput::initializeVarSets()
{
ui->labelInfoActive->setAlignment(Qt::AlignTop | Qt::AlignLeft);
ui->labelInfoActive->setWordWrap(true);
#if QT_VERSION >= QT_VERSION_CHECK(6,7,0)
connect(ui->checkBoxVarSets, &QCheckBox::checkStateChanged,
this, &DlgExpressionInput::onCheckVarSets);
@@ -441,7 +442,6 @@ static bool isNamePropOk(const QString& nameProp, App::DocumentObject* obj,
std::string name = nameProp.toStdString();
if (name.empty()) {
message << "Provide a name for the property.";
return false;
}
@@ -688,21 +688,22 @@ static bool isNameGroupOk(const QString& nameGroup,
return true;
}
void DlgExpressionInput::reportVarSetInfo(const char* message)
void DlgExpressionInput::reportVarSetInfo(const std::string& message)
{
ui->labelInfoActive->setText(QString::fromUtf8(message));
if (!message.empty()) {
FC_ERR(message);
}
}
bool DlgExpressionInput::reportGroup(QString& nameGroup)
{
if (nameGroup.isEmpty()) {
reportVarSetInfo("Provide a group.");
return true;
}
std::stringstream message;
if (!isNameGroupOk(nameGroup, message)) {
reportVarSetInfo(message.str().c_str());
reportVarSetInfo(message.str());
return true;
}
@@ -718,7 +719,7 @@ bool DlgExpressionInput::reportName(QTreeWidgetItem* item)
App::DocumentObject* obj = doc->getObject(nameVarSet.toUtf8());
std::stringstream message;
if (!isNamePropOk(nameProp, obj, message)) {
reportVarSetInfo(message.str().c_str());
reportVarSetInfo(message.str());
return true;
}
@@ -743,17 +744,17 @@ void DlgExpressionInput::updateVarSetInfo(bool checkExpr)
return;
}
QString nameProp = ui->lineEditPropNew->text();
QString labelVarSet = getValue(selected, ROLE_VARSET_LABEL);
QString nameDoc = getValue(selected, ROLE_DOC);
std::stringstream message;
message << "Adding property " << nameProp.toStdString() << std::endl
<< "of type " << getType() << std::endl
<< "to variable set " << labelVarSet.toStdString() << std::endl
<< "in group " << nameGroup.toStdString() << std::endl
<< "in document " << nameDoc.toStdString() << ".";
// QString nameProp = ui->lineEditPropNew->text();
// QString labelVarSet = getValue(selected, ROLE_VARSET_LABEL);
// QString nameDoc = getValue(selected, ROLE_DOC);
// std::stringstream message;
// message << "Adding property " << nameProp.toStdString() << std::endl
// << "of type " << getType() << std::endl
// << "to variable set " << labelVarSet.toStdString() << std::endl
// << "in group " << nameGroup.toStdString() << std::endl
// << "in document " << nameDoc.toStdString() << ".";
reportVarSetInfo(message.str().c_str());
// reportVarSetInfo(message.str().c_str());
if (checkExpr) {
// We have to check the text of the expression as well
try {
@@ -767,7 +768,6 @@ void DlgExpressionInput::updateVarSetInfo(bool checkExpr)
}
else {
okBtn->setEnabled(false);
reportVarSetInfo("Select a variable set.");
}
}

View File

@@ -94,7 +94,7 @@ private:
void checkExpression(const QString& text);
void setupVarSets();
std::string getType();
void reportVarSetInfo(const char* message);
void reportVarSetInfo(const std::string& message);
bool reportName(QTreeWidgetItem* item);
bool reportGroup(QString& nameGroup);
void updateVarSetInfo(bool checkExpr = true);

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>414</width>
<height>272</height>
<height>291</height>
</rect>
</property>
<property name="sizePolicy">
@@ -32,89 +32,6 @@
<property name="margin" stdset="0">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBoxVarSets">
<property name="title">
<string>Variable Sets</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<layout class="QGridLayout" name="gridLayoutVarSets">
<item row="1" column="2">
<widget class="QLineEdit" name="lineEditGroup"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelGroup">
<property name="text">
<string>Group</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="labelInfoActive">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>70</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelVarSet">
<property name="text">
<string>Variable set</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="comboBoxVarSet"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelInfo">
<property name="text">
<string>Info</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="LabelPropNew">
<property name="text">
<string>New property</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="lineEditPropNew">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxVarSets">
<property name="text">
<string>Show variable sets</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
@@ -131,10 +48,10 @@
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
@@ -202,7 +119,7 @@
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -235,7 +152,7 @@
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -250,31 +167,81 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Ok|QDialogButtonBox::StandardButton::Reset</set>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Reset|QDialogButtonBox::Ok</set>
<widget class="QCheckBox" name="checkBoxVarSets">
<property name="text">
<string>Add to variable set...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBoxVarSets">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<layout class="QGridLayout" name="gridLayoutVarSets">
<item row="2" column="2">
<widget class="QLineEdit" name="lineEditPropNew">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="LabelPropNew">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelVarSet">
<property name="text">
<string>Variable Set:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelGroup">
<property name="text">
<string>Group:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="comboBoxVarSet"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="lineEditGroup"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
@@ -296,7 +263,6 @@
<tabstops>
<tabstop>expression</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>checkBoxVarSets</tabstop>
</tabstops>
<resources/>
<connections>