Measure: Show delta option also in interactive mode (#16379)

* Initial commit to apply delta also for interactive measurement
* Not required special logic to check if possible, it can be easily checked if the property exists
* remember setting so it is not required to turn it always on
This commit is contained in:
Murmele
2024-09-10 04:39:27 +02:00
committed by GitHub
parent 7646d4b611
commit f7d5d9f0d8
2 changed files with 53 additions and 0 deletions

View File

@@ -32,6 +32,8 @@
#include <App/DocumentObjectGroup.h>
#include <App/Link.h>
#include <Mod/Measure/App/MeasureDistance.h>
#include <App/PropertyStandard.h>
#include <Gui/MainWindow.h>
#include <Gui/Application.h>
#include <Gui/BitmapFactory.h>
@@ -40,9 +42,15 @@
#include <QFormLayout>
#include <QPushButton>
#include <QSettings>
using namespace Gui;
namespace
{
constexpr auto taskMeasureSettingsGroup = "TaskMeasure";
constexpr auto taskMeasureShowDeltaSettingsName = "ShowDelta";
} // namespace
TaskMeasure::TaskMeasure()
{
@@ -54,6 +62,15 @@ TaskMeasure::TaskMeasure()
true,
nullptr);
QSettings settings;
settings.beginGroup(QLatin1String(taskMeasureSettingsGroup));
delta = settings.value(QLatin1String(taskMeasureShowDeltaSettingsName), true).toBool();
showDelta = new QCheckBox();
showDelta->setChecked(delta);
showDeltaLabel = new QLabel(tr("Show Delta:"));
connect(showDelta, &QCheckBox::stateChanged, this, &TaskMeasure::showDeltaChanged);
// Create mode dropdown and add all registered measuretypes
modeSwitch = new QComboBox();
modeSwitch->addItem(QString::fromLatin1("Auto"));
@@ -82,6 +99,7 @@ TaskMeasure::TaskMeasure()
formLayout->setFormAlignment(Qt::AlignCenter);
formLayout->addRow(tr("Mode:"), modeSwitch);
formLayout->addRow(showDeltaLabel, showDelta);
formLayout->addRow(tr("Result:"), valueResult);
layout->addLayout(formLayout);
@@ -319,6 +337,15 @@ void TaskMeasure::update()
valueResult->setText(_mMeasureObject->getResultString());
createViewObject(_mMeasureObject);
// Must be after createViewObject!
assert(_mViewObject);
auto* prop = dynamic_cast<App::PropertyBool*>(_mViewObject->getPropertyByName("ShowDelta"));
setDeltaPossible(prop != nullptr);
if (prop) {
prop->setValue(showDelta->isChecked());
_mViewObject->update(prop);
}
}
void TaskMeasure::close()
@@ -462,9 +489,27 @@ bool TaskMeasure::eventFilter(QObject* obj, QEvent* event)
return TaskDialog::eventFilter(obj, event);
}
void TaskMeasure::setDeltaPossible(bool possible)
{
showDelta->setVisible(possible);
showDeltaLabel->setVisible(possible);
}
void TaskMeasure::onModeChanged(int index)
{
explicitMode = (index != 0);
this->update();
}
void TaskMeasure::showDeltaChanged(int checkState)
{
delta = checkState == Qt::CheckState::Checked;
QSettings settings;
settings.beginGroup(QLatin1String(taskMeasureSettingsGroup));
settings.setValue(QLatin1String(taskMeasureShowDeltaSettingsName), delta);
this->update();
}

View File

@@ -24,6 +24,7 @@
#include <QString>
#include <QComboBox>
#include <QLineEdit>
#include <QCheckBox>
#include <App/Application.h>
#include <App/Document.h>
@@ -77,9 +78,12 @@ private:
QLineEdit* valueResult {nullptr};
QComboBox* modeSwitch {nullptr};
QCheckBox* showDelta {nullptr};
QLabel* showDeltaLabel {nullptr};
void removeObject();
void onModeChanged(int index);
void showDeltaChanged(int checkState);
void setModeSilent(App::MeasureType* mode);
App::MeasureType* getMeasureType();
void enableAnnotateButton(bool state);
@@ -87,6 +91,7 @@ private:
Gui::ViewProviderDocumentObject* createViewObject(App::DocumentObject* measureObj);
void saveObject();
void ensureGroup(Measure::MeasureBase* measurement);
void setDeltaPossible(bool possible);
// List of measure types
@@ -94,6 +99,9 @@ private:
// Stores if the mode is explicitly set by the user or implicitly through the selection
bool explicitMode = false;
// Stores if delta measures shall be shown
bool delta = true;
};
} // namespace Gui