Skip to content

Commit

Permalink
update auto-scale check box if changes in the color editor, re #11706
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed May 13, 2015
1 parent fd2feea commit 4e2ea6e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,22 @@ class EXPORT_OPT_MANTIDVATES_SIMPLEGUI_VIEWWIDGETS ColorSelectionWidget : public
double getMaxRange();
/// Load the default color map
void loadColorMap(bool viewSwitched);
/// Programmatically enable/disable auto scaling of color range
void setAutoScale(bool autoScale);
/// Set min smaller max, can be used to programmatically set the widgets
void setMinMax(double& min, double& max);
/// Others need to know if this widget is in the process of updating colors at user's request
bool inProcessUserRequestedAutoScale() { return m_inProcessUserRequestedAutoScale; };

public slots:
/// Set state for all control widgets.
void enableControls(bool state);
/// Reset the widget's state.
void reset();
/// Set the color scale range into the range widgets.
/// Set the color scale range into the range widgets (only in autoscale mode).
void setColorScaleRange(double min, double max);
/// Slot for when the user clicks on the auto-scale check box
void autoCheckBoxClicked(bool wasOnn);

signals:
/**
Expand All @@ -100,8 +108,6 @@ public slots:
void logScale(int state);

protected slots:
/// Set state of the automatic scaling checkbox.
void autoOrManualScaling(int state);
/// Get the new color scale range.
void getColorScaleRange();
/// Show available color presets.
Expand Down Expand Up @@ -137,6 +143,9 @@ protected slots:

pqColorPresetManager *m_presets; ///< Dialog for choosing color presets
Ui::ColorSelectionWidgetClass m_ui; ///< The mode control widget's UI form

/// this is a flag that is set while updating the color scale triggered by the user clicking on the auto-scale box
bool m_inProcessUserRequestedAutoScale;
};

} // SimpleGui
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <cfloat>
#include <iostream>

#include "MantidVatesSimpleGuiViewWidgets/ColorSelectionWidget.h"
#include "MantidKernel/ConfigService.h"
#include "MantidVatesSimpleGuiViewWidgets/ColorMapManager.h"
Expand Down Expand Up @@ -26,8 +29,6 @@
#include <QFile>
#include <QFileInfo>

#include <iostream>
#include <cfloat>

namespace Mantid
{
Expand All @@ -41,7 +42,9 @@ namespace SimpleGui
* sub-components and connections.
* @param parent the parent widget of the mode control widget
*/
ColorSelectionWidget::ColorSelectionWidget(QWidget *parent) : QWidget(parent), colorMapManager(new ColorMapManager()), m_minHistoric(0.01), m_maxHistoric(0.01)
ColorSelectionWidget::ColorSelectionWidget(QWidget *parent): QWidget(parent),
colorMapManager(new ColorMapManager()), m_minHistoric(0.01), m_maxHistoric(0.01),
m_inProcessUserRequestedAutoScale(false)
{
this->m_ui.setupUi(this);
this->m_ui.autoColorScaleCheckBox->setChecked(true);
Expand All @@ -58,20 +61,25 @@ namespace SimpleGui
this->m_ui.maxValLineEdit->setValidator(m_minValidator);
this->m_ui.minValLineEdit->setValidator(m_maxValidator);

QObject::connect(this->m_ui.autoColorScaleCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(autoOrManualScaling(int)));
QObject::connect(this->m_ui.autoColorScaleCheckBox, SIGNAL(clicked(bool)),
this, SLOT(autoCheckBoxClicked(bool)));

QObject::connect(this->m_ui.presetButton, SIGNAL(clicked()),
this, SLOT(loadPreset()));
this, SLOT(loadPreset()));

QObject::connect(this->m_ui.minValLineEdit, SIGNAL(editingFinished()),
this, SLOT(getColorScaleRange()));
this, SLOT(getColorScaleRange()));

QObject::connect(this->m_ui.maxValLineEdit, SIGNAL(editingFinished()),
this, SLOT(getColorScaleRange()));
this, SLOT(getColorScaleRange()));
QObject::connect(this->m_ui.useLogScaleCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(useLogScaling(int)));
}

/**
* This function sets the status of the color selection widgets.
* This function sets the status of the color selection min/max widgets. It
* doesn't modify the check boxes.
*
* @param status the state to set the color selection widgets to
*/
void ColorSelectionWidget::setEditorStatus(bool status)
Expand Down Expand Up @@ -190,23 +198,50 @@ void ColorSelectionWidget::addColorMapsFromXML(vtkPVXMLParser *parser,
}

/**
* This slot enables or diables the min and max line edits based on state
* of the automatic scaling checkbox.
* @param state the current state of the checkbox
* Changes the status of the autoScaling checkbox. This is in
* principle meant to be used programmatically, when for example the
* color map is edited elsewhere (like in the Paraview color editor).
*
* @param autoScale whether to set auto scaling (on/off)
*/
void ColorSelectionWidget::setAutoScale(bool autoScale)
{
this->m_ui.autoColorScaleCheckBox->setChecked(autoScale);
this->setEditorStatus(!autoScale);
}

/**
* Simply set the min and max values for the color scale.
*
* @param max maximum value (corresponding to the max line edit)
* @param min minimum value (corresponding to the max line edit)
*/
void ColorSelectionWidget::autoOrManualScaling(int state)
void ColorSelectionWidget::setMinMax(double& min, double& max)
{
switch (state)
setMinSmallerMax(min, max);
}

/**
* This slot enables or diables the min and max line edits based on
* the (changing) state of the automatic scaling checkbox. It should
* be used for click events on the auto-scale check box.
*
* @param wasOn current checked state (before the user clicks)
*/
void ColorSelectionWidget::autoCheckBoxClicked(bool wasOn)
{
m_inProcessUserRequestedAutoScale = true;
if (!wasOn)
{
case Qt::Unchecked:
this->setEditorStatus(true);
emit this->autoScale(this);
break;
case Qt::Checked:
}
else
{
this->setEditorStatus(false);
emit this->autoScale(this);
break;
}
m_inProcessUserRequestedAutoScale = false;
}

/**
Expand Down
31 changes: 27 additions & 4 deletions Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ColorUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <QColor>
#include <QList>

#include <QDebug>

namespace Mantid
{
// static logger
Expand Down Expand Up @@ -346,6 +348,7 @@ void ColorUpdater::colorScaleEditedCallbackFunc(vtkObject *caller, long unsigned
return;
}

// a pseudo-this
ColorUpdater *pThis = data->colorUpdater;
if (!pThis){
return;
Expand All @@ -356,6 +359,14 @@ void ColorUpdater::colorScaleEditedCallbackFunc(vtkObject *caller, long unsigned
return;
}

// This means that the user clicked on the auto-scale check box of the ColorSelectionWidget.
// That will change color properties of the ParaQ and trigger this callback. This condition
// prevents the callback from ruining the state of the ColorSelectionWidget (which is just
// being set by the user and we do not want to update programmatically in this case).
if (csel->inProcessUserRequestedAutoScale()) {
return;
}

// This vector has 4 values per color definition: data value (bin limit) + 3 R-G-B coordinates
vtkSMDoubleVectorProperty *RGBPoints = vtkSMDoubleVectorProperty::SafeDownCast(caller);
if (!RGBPoints)
Expand All @@ -365,12 +376,24 @@ void ColorUpdater::colorScaleEditedCallbackFunc(vtkObject *caller, long unsigned
int noe = RGBPoints->GetNumberOfElements();

// there should be at least one data value/bin + one triplet of R-G-B values
if (noe < 4)
const int subtract = 4;
if (noe < subtract)
return;

pThis->m_minScale = elems[0];
pThis->m_maxScale = elems[noe-4];
csel->setColorScaleRange(pThis->m_minScale, pThis->m_maxScale);
double newMin = elems[0];
double newMax = elems[noe-subtract];
if ((std::abs(newMin - csel->getMinRange()) > 1e-14) ||
(std::abs(csel->getMaxRange() - newMax) > 1e-14)
) {
pThis->m_minScale = newMin;
pThis->m_maxScale = newMax;
csel->setMinMax(pThis->m_minScale, pThis->m_maxScale);

if (csel->getAutoScaleState()) {
csel->setAutoScale(false);
pThis->m_autoScaleState = csel->getAutoScaleState();
}
}
}

}
Expand Down

0 comments on commit 4e2ea6e

Please sign in to comment.