Skip to content

Commit

Permalink
Merge branch 'feature/2480_show_required_props_and_default_vals_in_al…
Browse files Browse the repository at this point in the history
…g_diags' into develop

Conflicts:
	Code/Mantid/MantidQt/API/CMakeLists.txt

Refs #2480.
  • Loading branch information
PeterParker committed Apr 20, 2014
2 parents ffba77a + dc8a6cc commit 018a586
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Images/images.qrc
Expand Up @@ -11,6 +11,8 @@
<file>Mantid_Logo_Transparent.png</file>
<file>data_replace.png</file>
<file>panning.png</file>
<file>replace.png</file>
<file>restore.png</file>
</qresource>
<qresource prefix="/win">
<file>folder-remote.png</file>
Expand Down
Binary file added Code/Mantid/Images/replace.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Code/Mantid/Images/restore.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Code/Mantid/MantidQt/API/CMakeLists.txt
Expand Up @@ -18,6 +18,7 @@ set ( SRC_FILES
src/Message.cpp
src/OptionsPropertyWidget.cpp
src/PlotAxis.cpp
src/PropertyInfoWidget.cpp
src/PropertyWidget.cpp
src/PropertyWidgetFactory.cpp
src/PythonRunner.cpp
Expand All @@ -43,6 +44,7 @@ set ( MOC_FILES
inc/MantidQtAPI/MantidDialog.h
inc/MantidQtAPI/MantidWidget.h
inc/MantidQtAPI/OptionsPropertyWidget.h
inc/MantidQtAPI/PropertyInfoWidget.h
inc/MantidQtAPI/PropertyWidget.h
inc/MantidQtAPI/PythonRunner.h
inc/MantidQtAPI/QtSignalChannel.h
Expand Down
Expand Up @@ -45,7 +45,7 @@ namespace API
BoolPropertyWidget(Mantid::Kernel::PropertyWithValue<bool> * prop, QWidget * parent = NULL, QGridLayout * layout = NULL, int row=-1);
virtual ~BoolPropertyWidget();
QString getValue() const;
void setValue(const QString & value);
virtual void setValueImpl(const QString & value);

///@return the main widget of this combo of widgets
QWidget * getMainWidget() {return m_checkBox; }
Expand Down
Expand Up @@ -46,7 +46,7 @@ namespace API
OptionsPropertyWidget(Mantid::Kernel::Property * prop, QWidget * parent = NULL, QGridLayout * layout = NULL, int row=-1);
virtual ~OptionsPropertyWidget();
QString getValue() const;
void setValue(const QString & value);
virtual void setValueImpl(const QString & value);

///@return the main widget of this combo of widgets
QWidget * getMainWidget() {return m_combo; }
Expand Down
38 changes: 38 additions & 0 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/PropertyInfoWidget.h
@@ -0,0 +1,38 @@
#ifndef MANTID_API_PROPERTYINFOWIDGET_H
#define MANTID_API_PROPERTYINFOWIDGET_H

#include <QFrame>
#include <QMap>
#include <QLabel>

namespace MantidQt
{
namespace API
{
/**
* A widget used in dialogs to display various information about a property.
*/
class PropertyInfoWidget : public QFrame
{
Q_OBJECT;

public:
/// Enumerating the info that can be displayed by this widget.
enum Info { INVALID, REPLACE, RESTORE };

/// Constructor.
PropertyInfoWidget(QWidget *parent = 0);

/// Set the given icon's visibility.
void setInfoVisible( Info info, bool visible );
/// Set the given icon's tool tip.
void setInfoToolTip( Info info, const QString & toolTip );

private:
/// Map enum to labels.
QMap<Info, QLabel *> m_labels;
};
}
}

#endif /* MANTID_API_PROPERTYINFOWIDGET_H */
18 changes: 15 additions & 3 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/PropertyWidget.h
Expand Up @@ -5,6 +5,7 @@
#include <QtGui/qwidget.h>
#include <qgridlayout.h>
#include "MantidKernel/Property.h"
#include "MantidQtAPI/PropertyInfoWidget.h"
#include <QLabel>
#include <QtCore/qstring.h>
#include <qpushbutton.h>
Expand Down Expand Up @@ -56,7 +57,9 @@ namespace API
virtual QString getValue() const = 0;

/// Set the value of the property given into the GUI state.
virtual void setValue(const QString & value) = 0;
void setValue(const QString & value);
/// Set this widget's previously-entered value.
void setPreviousValue(const QString & previousValue);

virtual QWidget * getMainWidget() = 0;

Expand All @@ -79,6 +82,10 @@ namespace API

void setError(const QString & error);

private:
virtual void setValueImpl(const QString & value) = 0;
void setRestoredStatus();

public slots:
void replaceWSButtonClicked();

Expand Down Expand Up @@ -110,8 +117,8 @@ namespace API
/// If using the GridLayout, this is the row where the widget was inserted.
int m_row;

/// Label that is visible when the property is NOT valid.
QLabel * m_validLbl;
/// Widget to display information about this property.
PropertyInfoWidget * m_info;

/// Documentation string (tooltip)
QString m_doc;
Expand All @@ -124,6 +131,11 @@ namespace API

/// Error message received when trying to set the value
QString m_error;

/// Whether or not the property is an output workspace.
bool m_isOutputWsProp;

QString m_previousValue;
};


Expand Down
Expand Up @@ -45,7 +45,7 @@ namespace API
TextPropertyWidget(Mantid::Kernel::Property * prop, QWidget * parent = NULL, QGridLayout * layout = NULL, int row=-1);
virtual ~TextPropertyWidget();
QString getValue() const;
void setValue(const QString & value);
virtual void setValueImpl(const QString & value);

///@return the main widget of this combo of widgets
QWidget * getMainWidget() {return m_textbox; }
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp
Expand Up @@ -975,7 +975,7 @@ void AlgorithmDialog::setPreviousValue(QWidget* widget, const QString& propName)
PropertyWidget * propWidget = qobject_cast<PropertyWidget*>(widget);
if (propWidget)
{
propWidget->setValue(value);
propWidget->setPreviousValue(value);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/src/AlgorithmPropertiesWidget.cpp
Expand Up @@ -268,7 +268,7 @@ namespace API
if (!oldValue.isEmpty())
{
prop->setValue(oldValue.toStdString());
widget->setValue(oldValue);
widget->setPreviousValue(oldValue);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/src/BoolPropertyWidget.cpp
Expand Up @@ -47,7 +47,7 @@ namespace API
/** Set the value into the GUI
*
* @param value :: string representation of the value */
void BoolPropertyWidget::setValue(const QString & value)
void BoolPropertyWidget::setValueImpl(const QString & value)
{
QString temp = value;
if (temp.isEmpty())
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidQt/API/src/OptionsPropertyWidget.cpp
Expand Up @@ -67,7 +67,7 @@ namespace API
/** Set the value into the GUI
*
* @param value :: string representation of the value */
void OptionsPropertyWidget::setValue(const QString & value)
void OptionsPropertyWidget::setValueImpl(const QString & value)
{
QString temp = value;
if (temp.isEmpty())
Expand Down
73 changes: 73 additions & 0 deletions Code/Mantid/MantidQt/API/src/PropertyInfoWidget.cpp
@@ -0,0 +1,73 @@
#include "MantidQtAPI/PropertyInfoWidget.h"

#include <QHBoxLayout>
#include <QIcon>
#include <QPair>

namespace MantidQt
{
namespace API
{
/**
* Constructor.
*
* @param parent :: this widget's parent
*/
PropertyInfoWidget::PropertyInfoWidget(QWidget *parent)
: QFrame(parent), m_labels()
{
setLayout(new QHBoxLayout(this));
layout()->setSpacing(1);
layout()->setContentsMargins(0, 0, 0, 0);

QMap<Info, QPair<QString, QString>> pathsAndToolTips;
pathsAndToolTips[REPLACE] = QPair<QString, QString>(":/replace.png", "A workspace with this name already exists and so will be overwritten.");
pathsAndToolTips[RESTORE] = QPair<QString, QString>(":/restore.png", "This was a previously-entered value.");

foreach( const auto info, pathsAndToolTips.keys() )
{
const QString iconPath = pathsAndToolTips[info].first;
const QString toolTip = pathsAndToolTips[info].second;

auto label = new QLabel(this);
label->setPixmap(QPixmap(iconPath).scaledToHeight(15));
label->setVisible(false);
label->setToolTip(toolTip);

layout()->addWidget(label);
m_labels[info] = label;
}

auto label = new QLabel("*");
auto palette = label->palette();
palette.setColor(QPalette::WindowText, Qt::darkRed);
label->setPalette(palette);
label->setVisible(false);
layout()->addWidget(label);
m_labels[INVALID] = label;
}

/**
* Set the given icon's visibility.
*
* @param icon :: icon to set
* @param visible :: whether or not the icon should be visible
*/
void PropertyInfoWidget::setInfoVisible( Info info, bool visible )
{
m_labels[info]->setVisible(visible);
}

/**
* Set the given icon's tool tip.
*
* @param icon :: icon to set
* @param toolTip :: the contents of the tool tip
*/
void PropertyInfoWidget::setInfoToolTip( Info info, const QString & toolTip )
{
m_labels[info]->setToolTip(toolTip);
}

}//namespace
}//namespace
85 changes: 64 additions & 21 deletions Code/Mantid/MantidQt/API/src/PropertyWidget.cpp
Expand Up @@ -2,6 +2,8 @@
#include "MantidKernel/System.h"
#include "MantidKernel/EmptyValues.h"
#include "MantidAPI/IWorkspaceProperty.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidQtAPI/PropertyInfoWidget.h"

#include <boost/assign.hpp>

Expand Down Expand Up @@ -167,8 +169,9 @@ namespace API
*/
PropertyWidget::PropertyWidget(Mantid::Kernel::Property * prop, QWidget * parent, QGridLayout * layout, int row)
: QWidget(parent),
m_prop(prop), m_gridLayout(layout), m_row(row),
m_replaceWSButton(NULL)
m_prop(prop), m_gridLayout(layout), m_parent(NULL), m_row(row), m_info(NULL),
m_doc(), m_replaceWSButton(NULL), m_widgets(), m_error(), m_isOutputWsProp(false),
m_previousValue()
{
if (!prop)
throw std::runtime_error("NULL Property passed to the PropertyWidget constructor.");
Expand All @@ -190,21 +193,22 @@ namespace API
// Use the parent of the provided QGridLayout when adding widgets
m_parent = parent;
}

// Create the validator label (that red star)
m_validLbl = new QLabel("*");
QPalette pal = m_validLbl->palette();
pal.setColor(QPalette::WindowText, Qt::darkRed);
m_validLbl->setPalette(pal);
// Start off hidden
m_validLbl->setVisible(false);
// Put it in the 4th column.
m_gridLayout->addWidget(m_validLbl, m_row, 4);

m_info = new PropertyInfoWidget(this);
m_gridLayout->addWidget(m_info, m_row, 4);

/// Save the documentation tooltip
m_doc = QString::fromStdString(prop->documentation());


if( !isOptionalProperty(prop) )
{
if(!m_doc.isEmpty())
m_doc += "\n\n";
m_doc += "This property is required.";
}

if( prop->direction() == Direction::Output && dynamic_cast<IWorkspaceProperty*>(prop) )
m_isOutputWsProp = true;
}

//----------------------------------------------------------------------------------------------
Expand All @@ -214,6 +218,28 @@ namespace API
{
}

/**
* Set this widget's value.
*
* @param value :: the value to set
*/
void PropertyWidget::setValue(const QString & value)
{
setValueImpl(value);
setRestoredStatus();
}

/**
* Set this widget's value as a previously-entered value.
*
* @param previousValue :: the previous value of this widget
*/
void PropertyWidget::setPreviousValue(const QString & previousValue)
{
m_previousValue = previousValue;
setValue(previousValue);
}

//----------------------------------------------------------------------------------------------
/** Slot called when someone clicks the "replace ws button" */
void PropertyWidget::replaceWSButtonClicked()
Expand Down Expand Up @@ -243,6 +269,7 @@ namespace API
//m_wsbtn_tracker[btn ] = 1;
m_replaceWSButton->setToolTip("Replace input workspace");
connect(m_replaceWSButton, SIGNAL(clicked()), this, SLOT(replaceWSButtonClicked()));
connect(m_replaceWSButton, SIGNAL(clicked()), this, SLOT(valueChangedSlot()));
m_widgets.push_back(m_replaceWSButton);
// Place in the grid on column 2.
m_gridLayout->addWidget(m_replaceWSButton, m_row, 2);
Expand All @@ -260,14 +287,9 @@ namespace API
{
m_error = error.trimmed();

// Show the invalid star if there was an error
if (m_error.isEmpty())
m_validLbl->setVisible(false);
else
{
m_validLbl->setVisible(true);
m_validLbl->setToolTip(m_error);
}
// Show the invalid star if there was an error.
m_info->setInfoVisible(PropertyInfoWidget::INVALID, !m_error.isEmpty());
m_info->setInfoToolTip(PropertyInfoWidget::INVALID, m_error);
}


Expand Down Expand Up @@ -297,6 +319,14 @@ namespace API
}
this->setError(QString::fromStdString(error).trimmed());

setRestoredStatus();

if( m_isOutputWsProp )
{
const bool wsExists = Mantid::API::AnalysisDataService::Instance().doesExist(value.toStdString());
m_info->setInfoVisible(PropertyInfoWidget::REPLACE, wsExists);
}

// This will be caught by the GenericDialog.
emit valueChanged( QString::fromStdString(m_prop->name()) ) ;
}
Expand All @@ -321,6 +351,19 @@ namespace API
QWidget::setVisible(val);
}

/**
* "Nudge" the restored information icon.
*/
void PropertyWidget::setRestoredStatus()
{
if( m_previousValue == getValue() &&
getValue().toStdString() != m_prop->getDefault() &&
!getValue().isEmpty() )
m_info->setInfoVisible(PropertyInfoWidget::RESTORE, true);
else
m_info->setInfoVisible(PropertyInfoWidget::RESTORE, false);
}

/**
* Given a property and its associated label, will make font adjustments to the label
* based on whether or not the property is mandatory.
Expand Down

0 comments on commit 018a586

Please sign in to comment.