Commit 64ded787 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

cleanups to pqDoubleLineEdit

Make pqDoubleLineEdit not use a format specific double validator.
pqDoubleLineEdit should always accept any valid double string. It should
only change how it's shown based on the chosen format.

Now, pqDoubleLineEdit also doesn't attempt to cleanup a number entered
by the user. Thus, if user enter `1e10` for the full precision text, the
full precision text stays as so.

Changed default precision used by the widget to mixed rather than fixed.

(cherry picked from commit b02aa392)
parent 9ade7c3a
......@@ -24,7 +24,7 @@
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menuFilters" />
<pqevent object="pqClientMainWindow/menubar/menuFilters/Alphabetical" command="activate" arguments="WarpVector" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ScaleFactor/DoubleRangeWidget/DoubleLineEdit" property="fullPrecisionText" arguments="1.000000" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ScaleFactor/DoubleRangeWidget/DoubleLineEdit" property="fullPrecisionText" arguments="1" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ScaleFactor/Reset" command="activate" arguments="" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ScaleFactor/DoubleRangeWidget/DoubleLineEdit" property="fullPrecisionText" arguments="0.1702067740632144" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/ScaleFactor/ScaleBy/0.5X" command="activate" arguments="" />
......
......@@ -7,7 +7,7 @@
<pqevent object="pqClientMainWindow/FileOpenDialog" command="filesSelected" arguments="$PARAVIEW_DATA_ROOT/cinema-non-composite.cdb/image/info.json" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/DisplayFrame/ProxyPanel/RenderLayersAsImage/CheckBox" property="checked" arguments="false" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/Slider" property="value" arguments="0" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/DoubleLineEdit" property="fullPrecisionText" arguments="150.000000" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/DoubleLineEdit" property="fullPrecisionText" arguments="150" />
<pqevent object="pqClientMainWindow/cameraToolbar/actionRotate90degCW" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/cameraToolbar/actionNegativeZ" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/centralwidget/MultiViewWidget/CoreWidget/qt_tabwidget_stackedwidget/MultiViewWidget1/Frame.0/CentralWidgetFrame/Viewport" command="mousePress" arguments="(0.71194,0.511571,1,1,0)" />
......@@ -20,7 +20,7 @@
<pqevent object="pqClientMainWindow/pipelineBrowserDock/pipelineBrowser" command="mouseRelease" arguments="1,0,0,11,10,/0:0/0:1" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/Slider" command="set_int" arguments="1" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/DoubleLineEdit" property="fullPrecisionText" arguments="190.000000" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/DoubleLineEdit" property="fullPrecisionText" arguments="190" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/DoubleLineEdit" command="set_full_precision_text" arguments="220" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Contour1/DiscreteDoubleWidget/Slider" property="value" arguments="2" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
......
......@@ -9,7 +9,7 @@
<pqevent object="pqClientMainWindow/menubar" command="activate" arguments="menuFilters" />
<pqevent object="pqClientMainWindow/menubar/menuFilters/Chemistry" command="activate" arguments="ComputeMoleculeBonds" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/IsToleranceAbsolute/CheckBox" property="checked" arguments="true" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Tolerance/DoubleLineEdit0" property="text" arguments="0.450000" />
<pqcheck object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Tolerance/DoubleLineEdit0" property="text" arguments="0.45" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/scrollArea/qt_scrollarea_viewport/scrollAreaWidgetContents/PropertiesFrame/ProxyPanel/Tolerance/DoubleLineEdit0" command="set_full_precision_text" arguments="0.9" />
<pqevent object="pqClientMainWindow/propertiesDock/propertiesPanel/Accept" command="activate" arguments="" />
......
......@@ -374,7 +374,7 @@
<IntVectorProperty name="RealNumberDisplayedNotation"
number_of_elements="1"
default_values="2"
default_values="0"
command="SetRealNumberDisplayedNotation"
panel_visibility="advanced">
<Documentation>
......
......@@ -29,12 +29,13 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================*/
#include "pqSampleScalarAddRangeDialog.h"
#include "ui_pqSampleScalarAddRangeDialog.h"
#include "pqCoreUtilities.h"
#include <QIntValidator>
#include <algorithm>
#include <cmath>
......
......@@ -32,6 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqDoubleLineEdit.h"
// Qt Includes.
#include <QDoubleValidator>
#include <QFocusEvent>
#include <QPointer>
#include <QTextStream>
......@@ -56,25 +57,13 @@ QTextStream::RealNumberNotation toTextStreamNotation(pqDoubleLineEdit::RealNumbe
}
//-----------------------------------------------------------------------------
QDoubleValidator::Notation toValidatorNotation(pqDoubleLineEdit::RealNumberNotation notation)
{
if (notation != pqDoubleLineEdit::RealNumberNotation::FixedNotation)
{
return QDoubleValidator::ScientificNotation;
}
else
{
return QDoubleValidator::StandardNotation;
}
}
using InstanceTrackerType = QList<QPointer<pqDoubleLineEdit> >;
static InstanceTrackerType* InstanceTracker = nullptr;
}
int pqDoubleLineEdit::GlobalPrecision = 2;
int pqDoubleLineEdit::GlobalPrecision = 6;
pqDoubleLineEdit::RealNumberNotation pqDoubleLineEdit::GlobalNotation =
pqDoubleLineEdit::FixedNotation;
pqDoubleLineEdit::MixedNotation;
//-----------------------------------------------------------------------------
void pqDoubleLineEdit::setGlobalPrecisionAndNotation(int precision, RealNumberNotation notation)
......@@ -98,7 +87,6 @@ void pqDoubleLineEdit::setGlobalPrecisionAndNotation(int precision, RealNumberNo
{
if (instance && instance->useGlobalPrecisionAndNotation())
{
instance->updateFullPrecisionText();
instance->updateLimitedPrecisionText();
}
}
......@@ -123,8 +111,7 @@ pqDoubleLineEdit::pqDoubleLineEdit(QWidget* _parent)
, Precision(2)
, UseGlobalPrecisionAndNotation(true)
{
this->DoubleValidator = new QDoubleValidator(this);
this->setValidator(this->DoubleValidator);
this->setValidator(new QDoubleValidator(this));
this->setNotation(pqDoubleLineEdit::FixedNotation);
if (InstanceTracker == nullptr)
{
......@@ -161,7 +148,6 @@ void pqDoubleLineEdit::setFullPrecisionText(const QString& _text)
return;
}
this->FullPrecisionText = _text;
this->updateFullPrecisionText();
this->updateLimitedPrecisionText();
emit fullPrecisionTextChanged(this->FullPrecisionText);
}
......@@ -180,7 +166,6 @@ void pqDoubleLineEdit::setNotation(pqDoubleLineEdit::RealNumberNotation _notatio
return;
}
this->Notation = _notation;
this->DoubleValidator->setNotation(toValidatorNotation(_notation));
this->updateLimitedPrecisionText();
}
......@@ -198,30 +183,9 @@ void pqDoubleLineEdit::setPrecision(int _precision)
return;
}
this->Precision = _precision;
this->updateFullPrecisionText();
this->updateLimitedPrecisionText();
}
//-----------------------------------------------------------------------------
void pqDoubleLineEdit::setDoubleValidator(QDoubleValidator* validator)
{
if (validator == nullptr)
{
return;
}
validator->setParent(this);
this->setValidator(validator);
delete this->DoubleValidator;
this->DoubleValidator = validator;
this->DoubleValidator->setNotation(toValidatorNotation(this->notation()));
}
//-----------------------------------------------------------------------------
const QDoubleValidator* pqDoubleLineEdit::doubleValidator() const
{
return this->DoubleValidator;
}
//-----------------------------------------------------------------------------
void pqDoubleLineEdit::focusInEvent(QFocusEvent* event)
{
......@@ -232,38 +196,6 @@ void pqDoubleLineEdit::focusInEvent(QFocusEvent* event)
return this->Superclass::focusInEvent(event);
}
//-----------------------------------------------------------------------------
void pqDoubleLineEdit::updateFullPrecisionText()
{
const int real_precision =
this->UseGlobalPrecisionAndNotation ? pqDoubleLineEdit::GlobalPrecision : this->Precision;
int dotIndex = this->FullPrecisionText.indexOf(".");
if (dotIndex >= 0)
{
int digits = this->FullPrecisionText.length() - 1 - dotIndex;
if (digits <= real_precision)
{
// If it applies, appends "0"
this->FullPrecisionText += QString("0").repeated(real_precision - digits);
}
else
{
// If it applies, removes extra "0"
while (digits > this->Precision &&
this->FullPrecisionText[this->FullPrecisionText.length() - 1] == '0')
{
this->FullPrecisionText.chop(1);
digits = this->FullPrecisionText.length() - 1 - dotIndex;
}
}
}
else
{
this->FullPrecisionText += QString(".") + QString("0").repeated(real_precision);
}
}
//-----------------------------------------------------------------------------
void pqDoubleLineEdit::updateLimitedPrecisionText()
{
......
......@@ -33,8 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define pqDoubleLineEdit_h
// Qt Includes.
#include <QDoubleValidator>
class QFocusEvent;
#include <QLineEdit>
// ParaView Includes.
......@@ -46,6 +44,9 @@ class QFocusEvent;
*
* The precision and notation associated with the displayed number can be
* configured using the corresponding properties.
*
* In its constructor, pqDoubleLineEdit sets up a QDoubleValidator as the
* validator for the line edit.
*/
class PQWIDGETS_EXPORT pqDoubleLineEdit : public QLineEdit
{
......@@ -91,19 +92,6 @@ public:
*/
int precision() const;
/**
* Set a new instance of input validator. Note that setting a null pointer has no effect
* and that the ownership of the validator is transfer to this pqDoubleLineEdit instance.
* \sa doubleValidator()
*/
void setDoubleValidator(QDoubleValidator* validator);
/**
* Return a pointer to the current input validator.
* \sa setDoubleValidator()
*/
const QDoubleValidator* doubleValidator() const;
/**
* `useGlobalPrecisionAndNotation` indicates if the pqDoubleLineEdit should
* use global precision and notation values instead of the parameters
......@@ -180,7 +168,6 @@ protected slots:
protected:
void focusInEvent(QFocusEvent* event) override;
void updateFullPrecisionText();
void updateLimitedPrecisionText();
private:
......@@ -188,7 +175,7 @@ private:
QString FullPrecisionText;
RealNumberNotation Notation;
QDoubleValidator* DoubleValidator;
int Precision;
bool UseGlobalPrecisionAndNotation;
......
......@@ -128,7 +128,7 @@ void pqDoubleRangeWidget::updateValidator()
//-----------------------------------------------------------------------------
bool pqDoubleRangeWidget::strictRange() const
{
const QDoubleValidator* dv = validator();
const QDoubleValidator* dv = this->validator();
return dv->bottom() == this->minimum() && dv->top() == this->maximum();
}
......
......@@ -137,13 +137,13 @@ void pqDoubleSliderWidget::editingFinished()
//-----------------------------------------------------------------------------
void pqDoubleSliderWidget::setValidator(QDoubleValidator* validator)
{
this->DoubleLineEdit->setDoubleValidator(validator);
this->DoubleLineEdit->setValidator(validator);
}
//-----------------------------------------------------------------------------
const QDoubleValidator* pqDoubleSliderWidget::validator() const
{
return this->DoubleLineEdit->doubleValidator();
return qobject_cast<const QDoubleValidator*>(this->DoubleLineEdit->validator());
}
//-----------------------------------------------------------------------------
......
......@@ -19,8 +19,8 @@
#include "pqWidgetsModule.h"
#include <QWidget>
class QSlider;
class QDoubleValidator;
class QSlider;
/**
* A widget with a tied slider and line edit for editing a double property
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment