Commit 0df93a91 authored by Fredrik Edemar's avatar Fredrik Edemar

* Load constants properly when two value names are equal.

* Clear the parameter list when "no parameter values" is selected in the plot function dialog.
* Removed unused constructors in KConstantEditor, KEditConstant and KParameterEditor.
* Delete the dialog KEditConstant when the user is closing it.
* Select the constant or value textbox in KEditConstant::cmdOK_clicked() when something goes wrong.
* In KEditConstant: the members "constant" and "value" are now refererences instead of pointers as it gains performance and makes it easier to read.
* Better adding and editing parameter values in KParameterEditor.
* Added more comments.

CCMAIL:kdmoeller@foni.net
CCMAIL:bmlmessmer@web.de

svn path=/trunk/kdeedu/kmplot/; revision=327703
parent 031c106f
......@@ -615,21 +615,33 @@ void MainDlg::loadConstants()
constant = 'A';
if ( tmp_constant == " " || value == 1.23456789)
return;
bool stop = false;
if ( !view->parser()->constant.empty() )
for( ; !stop;constant++)
{
bool copy_found=false;
while (!copy_found)
{
for( int k = 0; k< (int)view->parser()->constant.size() && !stop;k++)
// go through the constant list
QValueVector<Constant>::iterator it = view->parser()->constant.begin();
while (it!= view->parser()->constant.end() && !copy_found)
{
if (constant == it->constant )
copy_found = true;
else
++it;
}
if ( !copy_found)
copy_found = true;
else
{
if (constant != view->parser()->constant[k].constant)
{
constant = view->parser()->constant[k].constant;
stop = true;
}
copy_found = false;
if (constant == 'Z')
constant = 'A';
else
constant++;
}
if (constant == 'Z')
constant = 'A'-1;
}
}
/*kdDebug() << "**************" << endl;
kdDebug() << "C:" << constant << endl;
kdDebug() << "V:" << value << endl;*/
......
......@@ -48,13 +48,14 @@ class XParser;
class KMinMax;
class SliderWindow;
/// The progress-widget in the statusbar which appears when drawing integrals
class KmPlotProgress: public QWidget
{
public:
KmPlotProgress( QWidget* parent = 0, const char* name = 0 );
~KmPlotProgress();
void increase();
KPushButton *button;
KProgress *progress;
};
......@@ -117,7 +118,7 @@ public:
/// Slider controlling parameter values
SliderWindow* sliders[ SLIDER_COUNT ];
void updateSliders(); //< show only needed sliders
void updateSliders(); /// show only needed sliders
public slots:
/// Called when the user want to cancel the drawing
......@@ -148,7 +149,7 @@ protected slots:
void keyPressEvent(QKeyEvent * );
/// called when a mouse key is released
void mouseReleaseEvent ( QMouseEvent * e );
/// Is needed to be reimplement so that the user can stop a preview-drawing
bool event( QEvent * e );
private:
......
......@@ -306,22 +306,26 @@ void EditFunction::accept()
else
tmp_fktext.f_mode = 1;
tmp_fktext.k_anz = 0;
if( editfunctionpage->useSlider->isChecked() )
tmp_fktext.use_slider = editfunctionpage->listOfSliders->currentItem(); //specify which slider that will be used
else
tmp_fktext.use_slider = -1;
tmp_fktext.k_anz = 0;
if( !m_parameter.isEmpty() )
{
tmp_fktext.str_parameter = m_parameter;
for( QStringList::Iterator it = m_parameter.begin(); it != m_parameter.end(); ++it )
tmp_fktext.use_slider = -1;
if ( editfunctionpage->useNoParameter->isChecked() || m_parameter.isEmpty() )
m_parameter.clear();
else
{
tmp_fktext.k_liste[ tmp_fktext.k_anz ] = m_parser->eval(( *it ) );
tmp_fktext.k_anz++;
tmp_fktext.str_parameter = m_parameter;
for( QStringList::Iterator it = m_parameter.begin(); it != m_parameter.end(); ++it )
{
tmp_fktext.k_liste[ tmp_fktext.k_anz ] = m_parser->eval(( *it ) );
tmp_fktext.k_anz++;
}
}
}
if( editderivativespage->showDerivative1->isChecked() )
tmp_fktext.f1_mode = 1;
else
......
......@@ -41,11 +41,6 @@
#include "kconstanteditor.h"
KConstantEditor::KConstantEditor(QWidget *parent, const char *name)
: QConstantEditor(parent, name)
{
}
KConstantEditor::KConstantEditor(View *v, QWidget *parent, const char *name)
: QConstantEditor(parent,name), m_view(v)
{
......@@ -80,7 +75,6 @@ void KConstantEditor::cmdEdit_clicked()
KEditConstant *dlg = new KEditConstant(m_view->parser(), constant, value);
connect( dlg, SIGNAL( finished() ), this,SLOT(editConstantSlot() ) );
dlg->txtConstant->setEnabled(false);
dlg->show();
}
......
......@@ -37,18 +37,23 @@ class KConstantEditor : public QConstantEditor
{
Q_OBJECT
public:
KConstantEditor(QWidget *parent = 0, const char *name = 0);
KConstantEditor(View *, QWidget *parent = 0, const char *name = 0);
~KConstantEditor();
public slots:
/// actions for the buttons
void cmdNew_clicked();
void cmdEdit_clicked();
void cmdDelete_clicked();
void cmdDuplicate_clicked();
///actions for the visible constant list
void varlist_clicked( QListViewItem * item );
void varlist_doubleClicked( QListViewItem * );
void cmdDuplicate_clicked();
/// called when a user pressed OK the the new-constant-dialog
void newConstantSlot();
/// called when a user pressed OK the the edit-constant-dialog
void editConstantSlot();
......
......@@ -32,22 +32,16 @@
#include "keditconstant.h"
KEditConstant::KEditConstant(QWidget *parent, const char *name)
: QEditConstant(parent, name)
{
}
KEditConstant::KEditConstant(XParser *p, char &c, QString &v, QWidget *parent, const char *name)
: QEditConstant(parent, name)
: QEditConstant(parent, name,Qt::WDestructiveClose), constant(c), value(v), m_parser(p)
{
constant = &c;
value = &v;
m_parser = p;
if ( *constant != '0' )
if ( constant != '0' )
{
txtConstant->setText(QChar(*constant));
txtValue->setText(*value);
txtConstant->setEnabled(false);
txtConstant->setText(QChar(constant));
txtValue->setText(value);
txtValue->setFocus();
txtValue->selectAll();
}
connect( cmdCancel, SIGNAL( clicked() ), this, SLOT( deleteLater() ));
connect( cmdOK, SIGNAL( clicked() ), this, SLOT( cmdOK_clicked() ));
......@@ -60,21 +54,23 @@ KEditConstant::~KEditConstant()
void KEditConstant::cmdOK_clicked()
{
*constant = txtConstant->text().at(0).latin1();
*value = txtValue->text();
if ( *constant<'A' || *constant>'Z')
constant = txtConstant->text().at(0).latin1();
value = txtValue->text();
if ( constant<'A' || constant>'Z')
{
KMessageBox::error(this, i18n("Please insert a valid constant name between A and Z."));
txtConstant->setFocus();
txtConstant->selectAll();
return;
}
if ( txtConstant->isEnabled() ) //creating, not edit a constant
{
bool found= false;
QValueVector<Constant>::iterator it;
for(it = m_parser->constant.begin(); it!= m_parser->constant.end() && !found;it++)
{
if ( it->constant == *constant)
if ( it->constant == constant)
found = true;
}
if (found)
......@@ -83,9 +79,13 @@ void KEditConstant::cmdOK_clicked()
return;
}
}
(double) m_parser->eval(*value);
(double) m_parser->eval(value);
if ( m_parser->errmsg() )
{
txtValue->setFocus();
txtValue->selectAll();
return;
}
emit finished();
QDialog::accept();
......@@ -96,4 +96,4 @@ void KEditConstant::txtVariable_lostFocus()
txtConstant->setText( txtConstant->text().upper() );
}
#include "keditconstant.moc"
#include "keditconstant.moc"
\ No newline at end of file
......@@ -36,7 +36,6 @@ class KEditConstant : public QEditConstant
{
Q_OBJECT
public:
KEditConstant(QWidget *parent = 0, const char *name = 0);
KEditConstant(XParser *p, char &, QString &,QWidget *parent = 0, const char *name = 0);
~KEditConstant();
......@@ -44,15 +43,17 @@ public:
public slots:
void cmdOK_clicked();
void txtVariable_lostFocus();
signals:
/// called when we are finished
void finished();
private:
char *constant;
QString *value;
char &constant;
QString &value;
XParser *m_parser;
};
#endif
#endif
\ No newline at end of file
......@@ -36,11 +36,6 @@
#include "kparametereditor.h"
KParameterEditor::KParameterEditor(QWidget *parent, const char *name)
: QParameterEditor(parent, name)
{
}
KParameterEditor::KParameterEditor(XParser *m, QStringList *l, QWidget *parent, const char *name)
: QParameterEditor(parent,name, true, Qt::WDestructiveClose), m_parameter(l), m_parser(m)
{
......@@ -70,48 +65,56 @@ KParameterEditor::~KParameterEditor()
void KParameterEditor::cmdNew_clicked()
{
bool ok;
QString result = KInputDialog::getText( i18n("Parameter Value"), i18n( "Enter a new parameter value:" ), QString::null, &ok );
if ( !ok)
return;
m_parser->eval( result );
if ( m_parser->err != 0 )
{
m_parser->errmsg();
cmdNew_clicked();
return;
}
if ( checkTwoOfIt(result) )
QString result="";
while (1)
{
KMessageBox::error(0,i18n("The value %1 already exists and will therefore not be added.").arg(result));
return;
bool ok;
result = KInputDialog::getText( i18n("Parameter Value"), i18n( "Enter a new parameter value:" ), result, &ok );
if ( !ok)
return;
m_parser->eval( result );
if ( m_parser->err != 0 )
{
m_parser->errmsg();
continue;
}
if ( checkTwoOfIt(result) )
{
KMessageBox::error(0,i18n("The value %1 already exists and will therefore not be added.").arg(result));
continue;
}
list->insertItem(result);
list->sort();
break;
}
list->insertItem(result);
list->sort();
}
void KParameterEditor::cmdEdit_clicked()
{
bool ok;
QString result = KInputDialog::getText( i18n("Parameter Value"), i18n( "Enter a new parameter value:" ), list->currentText(), &ok );
if ( !ok)
return;
m_parser->eval(result);
if ( m_parser->err != 0 && checkTwoOfIt(result))
{
m_parser->errmsg();
cmdNew_clicked();
return;
}
if ( checkTwoOfIt(result) )
QString result=list->currentText();
while (1)
{
if( result != list->currentText() )
KMessageBox::error(0,i18n("The value %1 already exists.").arg(result));
return;
bool ok;
result = KInputDialog::getText( i18n("Parameter Value"), i18n( "Enter a new parameter value:" ), result, &ok );
if ( !ok)
return;
m_parser->eval(result);
if ( m_parser->err != 0)
{
m_parser->errmsg();
continue;
}
if ( checkTwoOfIt(result) )
{
if( result != list->currentText() )
KMessageBox::error(0,i18n("The value %1 already exists.").arg(result));
continue;
}
list->removeItem( list->currentItem());
list->insertItem(result);
list->sort();
break;
}
list->removeItem( list->currentItem());
list->insertItem(result);
list->sort();
}
void KParameterEditor::cmdDelete_clicked()
......
......@@ -37,7 +37,6 @@ class KParameterEditor : public QParameterEditor
{
Q_OBJECT
public:
KParameterEditor(QWidget *parent = 0, const char *name = 0);
KParameterEditor(XParser *, QStringList *, QWidget *parent = 0, const char *name = 0);
~KParameterEditor();
......
......@@ -219,7 +219,7 @@ void XParser::fixFunctionName( QString &str, int const index)
}
void XParser::euler_method(double &x, double &y,const int &index)
void XParser::euler_method(double &x, double &y,const int &index)
{
// y == the old yprim-value
......
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