Commit 50dc19fa authored by David Saxton's avatar David Saxton

Usability improvements to dealing of parameters:

- Warn if the parameter animator is invoked when the function does not have a parameter.
- Automatically insert a parameter into the function string if Use List or Use Slider (in parameters groupbox) are clicked.

svn path=/trunk/KDE/kdeedu/kmplot/; revision=569600
parent c899ecdf
......@@ -115,6 +115,11 @@ class EquationEdit : public QWidget
* Changes the equation type.
*/
void setEquationType( Equation::Type type );
/**
* \return a pointer that the equation that this equation edit uses for
* validation, etc.
*/
Equation * equation() const { return m_equation; }
/**
* For inserting the currently selected text into a function. For
* example, if "2+x" is selected, \p before is "sin(" and \p after is
......
......@@ -94,21 +94,26 @@ FunctionEditor::FunctionEditor( KMenu * createNewPlotsMenu, QWidget * parent )
//BEGIN initialize equation edits
m_editor->cartesianEquation->setInputType( EquationEdit::Function );
m_editor->cartesianEquation->setEquationType( Equation::Cartesian );
m_editor->cartesianParameters->associateEquationEdit( m_editor->cartesianEquation );
m_editor->polarEquation->setInputType( EquationEdit::Function );
m_editor->polarEquation->setEquationType( Equation::Polar );
m_editor->polarParameters->associateEquationEdit( m_editor->polarEquation );
m_editor->parametricX->setInputType( EquationEdit::Function );
m_editor->parametricX->setEquationType( Equation::ParametricX );
m_editor->parametricParameters->associateEquationEdit( m_editor->parametricX );
m_editor->parametricY->setInputType( EquationEdit::Function );
m_editor->parametricY->setEquationType( Equation::ParametricY );
m_editor->parametricParameters->associateEquationEdit( m_editor->parametricY );
m_editor->implicitEquation->setInputType( EquationEdit::Function );
m_editor->implicitEquation->setEquationType( Equation::Implicit );
m_editor->differentialEquation->setInputType( EquationEdit::Function );
m_editor->differentialEquation->setEquationType( Equation::Differential );
m_editor->differentialParameters->associateEquationEdit( m_editor->differentialEquation );
//END initialize equation edits
for ( unsigned i = 0; i < 5; ++i )
......
......@@ -60,6 +60,9 @@ ParameterAnimator::ParameterAnimator( QWidget * parent, Function * function )
m_function->m_parameters.animating = true;
m_function->k = m_currentValue;
if ( function->eq[0]->usesParameter() )
m_widget->warningLabel->hide();
m_timer = new QTimer( this );
connect( m_timer, SIGNAL(timeout()), this, SLOT(step()) );
......
......@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>305</width>
<height>339</height>
<width>411</width>
<height>460</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -19,6 +19,22 @@
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="warningLabel" >
<property name="toolTip" >
<string>The function must have an additional variable as a parameter, e.g. f(x,k) would have k as its parameter</string>
</property>
<property name="text" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:Sans Serif; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:Sans;">&lt;span style=" font-weight:600;">Warning:&lt;/span> The current function does not have a parameter, and so cannot be animated.&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="wordWrap" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" >
<property name="margin" >
......@@ -300,8 +316,8 @@
</property>
<property name="sizeHint" >
<size>
<width>281</width>
<height>51</height>
<width>261</width>
<height>81</height>
</size>
</property>
</spacer>
......@@ -310,8 +326,13 @@
</widget>
<customwidgets>
<customwidget>
<class>EquationEdit</class>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>EquationEdit</class>
<extends>KLineEdit</extends>
<header>equationedit.h</header>
</customwidget>
</customwidgets>
......
......@@ -38,6 +38,8 @@ ParametersWidget::ParametersWidget( QWidget * parent )
listOfSliders->addItem( i18n( "Slider No. %1", number +1) );
connect( editParameterListButton, SIGNAL(clicked()), this, SLOT(editParameterList()) );
connect( useSlider, SIGNAL(toggled(bool)), this, SLOT(updateEquationEdits()) );
connect( useList, SIGNAL(toggled(bool)), this, SLOT(updateEquationEdits()) );
}
......@@ -71,6 +73,36 @@ void ParametersWidget::editParameterList()
dlg->exec();
emit parameterListChanged();
}
void ParametersWidget::updateEquationEdits( )
{
if ( !useSlider->isChecked() && !useList->isChecked() )
{
// Don't need to add any parameter variables
return;
}
foreach ( EquationEdit * edit, m_equationEdits )
{
if ( edit->equation()->usesParameter() || !edit->equation()->looksLikeFunction() )
continue;
QString text = edit->text();
int bracket = text.indexOf( ')' );
if ( bracket < 0 )
continue;
text.replace( bracket, 1, ",k)" );
edit->setText( text );
}
}
void ParametersWidget::associateEquationEdit( EquationEdit * edit )
{
m_equationEdits << edit;
}
//END class ParametersWidget
#include "parameterswidget.moc"
......@@ -29,6 +29,8 @@
#include "ui_parameterswidget.h"
class EquationEdit;
class ParametersWidget : public QGroupBox, public Ui_ParametersWidget
{
Q_OBJECT
......@@ -44,6 +46,14 @@ class ParametersWidget : public QGroupBox, public Ui_ParametersWidget
* \return the current settings as specified in the widgets.
*/
ParameterSettings parameterSettings() const;
/**
* The ParametersWidget can make sure that when the user wants to use
* a parameter (i.e. the Use List checkbox or Use Slider checkbox is
* checked), the function string has a parameter variable. Use this
* to add an EquationEdit for a function string that ParametersWidget
* will update when necessary.
*/
void associateEquationEdit( EquationEdit * edit );
signals:
/**
......@@ -51,11 +61,15 @@ class ParametersWidget : public QGroupBox, public Ui_ParametersWidget
*/
void parameterListChanged();
public slots:
private slots:
/**
* Called when the "Edit [parameter] List" button is clicked.
*/
void editParameterList();
/**
* Called when one of the checkboxes is checked.
*/
void updateEquationEdits();
protected:
/**
......@@ -63,6 +77,10 @@ class ParametersWidget : public QGroupBox, public Ui_ParametersWidget
* to its parameter list.
*/
QList<Value> m_parameters;
/**
* The list of equation edits that may be updated. See sassociateEquationEdit.
*/
QList<EquationEdit*> m_equationEdits;
};
#endif
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