Add unit aware preferences widget

This commit is contained in:
wmayer
2018-03-07 14:34:53 +01:00
parent 7af5dac2bb
commit 2900fb29c9
4 changed files with 59 additions and 0 deletions

View File

@@ -457,6 +457,39 @@ void PrefColorButton::savePreferences()
// --------------------------------------------------------------------
PrefUnitSpinBox::PrefUnitSpinBox ( QWidget * parent )
: QuantitySpinBox(parent), PrefWidget()
{
}
PrefUnitSpinBox::~PrefUnitSpinBox()
{
}
void PrefUnitSpinBox::restorePreferences()
{
if (getWindowParameter().isNull()) {
Console().Warning("Cannot restore!\n");
return;
}
double fVal = (double)getWindowParameter()->GetFloat( entryName() ,rawValue() );
setValue(fVal);
}
void PrefUnitSpinBox::savePreferences()
{
if (getWindowParameter().isNull()) {
Console().Warning("Cannot save!\n");
return;
}
double q = rawValue();
getWindowParameter()->SetFloat( entryName(), q );
}
// --------------------------------------------------------------------
namespace Gui {
class PrefQuantitySpinBoxPrivate
{

View File

@@ -275,6 +275,28 @@ protected:
void savePreferences();
};
/** The PrefUnitSpinBox class.
* \author wandererfan
* a simple Unit aware spin box.
* See also \ref PrefQuantitySpinBox
*/
class GuiExport PrefUnitSpinBox : public QuantitySpinBox, public PrefWidget
{
Q_OBJECT
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
public:
PrefUnitSpinBox ( QWidget * parent = 0 );
virtual ~PrefUnitSpinBox();
protected:
// restore from/save to parameters
void restorePreferences();
void savePreferences();
};
class PrefQuantitySpinBoxPrivate;
/**

View File

@@ -175,6 +175,7 @@ void PreferenceUiForm::loadSettings()
loadPrefWidgets<Gui::PrefRadioButton *>();
loadPrefWidgets<Gui::PrefSlider *>();
loadPrefWidgets<Gui::PrefColorButton *>();
loadPrefWidgets<Gui::PrefUnitSpinBox *>();
}
void PreferenceUiForm::saveSettings()
@@ -192,6 +193,7 @@ void PreferenceUiForm::saveSettings()
savePrefWidgets<Gui::PrefRadioButton *>();
savePrefWidgets<Gui::PrefSlider *>();
savePrefWidgets<Gui::PrefColorButton *>();
savePrefWidgets<Gui::PrefUnitSpinBox *>();
}
// ----------------------------------------------------------------

View File

@@ -96,6 +96,8 @@ WidgetFactorySupplier::WidgetFactorySupplier()
new WidgetProducer<Gui::PrefSlider>;
new WidgetProducer<Gui::PrefFileChooser>;
new WidgetProducer<Gui::PrefColorButton>;
new WidgetProducer<Gui::PrefUnitSpinBox>;
new WidgetProducer<Gui::PrefQuantitySpinBox>;
new WidgetProducer<Gui::CommandIconView>;
new WidgetProducer<Gui::AccelLineEdit>;
new WidgetProducer<Gui::ActionSelector>;