Commit 30af5e2a authored by Fredrik Edemar's avatar Fredrik Edemar

* Use fixFunctionName for polar functions.

* Don't change the function name when editing a function with uses fixFunctionName.
* Set the focus on the min-textbox when KMinMax is opened.
* Make findFunctionName private.
* Don't show the min- and maxrangevalue if it's not necessary.
* Set the calculate-button in KMinMax to default.

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

svn path=/trunk/kdeedu/kmplot/; revision=321937
parent 8f946664
......@@ -147,8 +147,8 @@ void FktDlg::slotEditFunction( int index, int num )
editFunction->initDialog( index );
if( editFunction->exec() == QDialog::Accepted )
{
if( index == -1 ) lb_fktliste->insertItem( editFunction->functionItem() );
else lb_fktliste->changeItem( editFunction->functionItem(), num );
if( index == -1 ) lb_fktliste->insertItem( editFunction->functionItem() ); //a new function
else lb_fktliste->changeItem( editFunction->functionItem(), num ); //changed a function
changed = true;
updateView();
}
......@@ -161,9 +161,8 @@ void FktDlg::slotEditParametric( int x_index, int y_index, int num )
editParametric->initDialog( x_index, y_index );
if( editParametric->exec() == QDialog::Accepted )
{
if( x_index == -1 )
lb_fktliste->insertItem( editParametric->functionItem() );
else lb_fktliste->changeItem( editParametric->functionItem(), num );
if( x_index == -1 ) lb_fktliste->insertItem( editParametric->functionItem() ); //a new function
else lb_fktliste->changeItem( editParametric->functionItem(), num ); //changed a function
changed = true;
updateView();
}
......@@ -176,8 +175,8 @@ void FktDlg::slotEditPolar( int index, int num )
editPolar->initDialog( index );
if( editPolar->exec() == QDialog::Accepted )
{
if( index == -1 ) lb_fktliste->insertItem( editPolar->functionItem() );
else lb_fktliste->changeItem( editPolar->functionItem(), num );
if( index == -1 ) lb_fktliste->insertItem( editPolar->functionItem() ); //a new function
else lb_fktliste->changeItem( editPolar->functionItem(), num ); //changed a function
changed = true;
updateView();
}
......
......@@ -168,11 +168,11 @@ void EditFunction::accept()
return;
QString f_str(functionItem() );
m_parser->fixFunctionName(f_str);
int index;
if( m_index != -1 ) //when editing a function:
{
index = m_index; //use the right function-index
m_parser->fixFunctionName(f_str,index);
QString old_fstr = m_parser->ufkt[index].fstr;
m_parser->ufkt[index].fstr = f_str;
m_parser->reparse(index); //reparse the funcion
......@@ -188,7 +188,10 @@ void EditFunction::accept()
}
}
else
{
m_parser->fixFunctionName(f_str);
index = m_parser->addfkt( f_str ); //create a new function otherwise
}
if( index == -1)
{
......@@ -358,6 +361,7 @@ void EditFunction::accept()
}
m_parser->fktext[index] = tmp_fktext;
editfunctionpage->equation->setText(f_str);
// call inherited method
KDialogBase::accept();
......
......@@ -76,9 +76,14 @@ void KEditParametric::setWidgets()
splitEquation( m_parser->fktext[ m_y_index ].extstr, name, expression );
kLineEditYFunction->setText( expression );
checkBoxHide->setChecked( m_parser->fktext[ m_x_index ].f_mode == 0 );
checkBoxRange->setChecked( m_parser->fktext[ m_x_index ].dmin == m_parser->fktext[ m_x_index ].dmax == 0 );
min->setText( m_parser->fktext[ m_x_index ].str_dmin );
max->setText( m_parser->fktext[ m_x_index ].str_dmax );
if ( m_parser->fktext[ m_x_index ].dmin != m_parser->fktext[ m_x_index ].dmax )
{
checkBoxRange->setChecked(true);
min->setText( m_parser->fktext[ m_x_index ].str_dmin );
max->setText( m_parser->fktext[ m_x_index ].str_dmax );
}
else
checkBoxRange->setChecked(false);
kIntNumInputLineWidth->setValue( m_parser->fktext[ m_x_index ].linewidth );
kColorButtonColor->setColor( m_parser->fktext[ m_x_index ].color );
}
......
......@@ -71,21 +71,29 @@ void KEditPolar::setWidgets()
function = function.right( function.length()-1 );
kLineEditYFunction->setText( function );
checkBoxHide->setChecked( m_parser->fktext[ m_index ].f_mode == 0 );
checkBoxRange->setChecked( m_parser->fktext[ m_index ].dmin == m_parser->fktext[ m_index ].dmax == 0.0 );
min->setText( m_parser->fktext[ m_index ].str_dmin );
max->setText( m_parser->fktext[ m_index ].str_dmax );
if ( m_parser->fktext[ m_index ].dmin != m_parser->fktext[ m_index ].dmax )
{
checkBoxRange->setChecked( true );
min->setText( m_parser->fktext[ m_index ].str_dmin );
max->setText( m_parser->fktext[ m_index ].str_dmax );
}
else
checkBoxRange->setChecked( false );
kIntNumInputLineWidth->setValue( m_parser->fktext[ m_index ].linewidth );
kColorButtonColor->setColor( m_parser->fktext[ m_index ].color );
}
void KEditPolar::accept()
{
QString f_str = kLineEditYFunction->text();
int index;
if( m_index != -1 ) //when editing a function:
{
index = m_index; //use the right function-index
m_parser->fixFunctionName(f_str,index);
f_str.prepend("r");
QString old_fstr = m_parser->ufkt[index].fstr;
m_parser->ufkt[index].fstr = functionItem();
m_parser->ufkt[index].fstr = f_str;
m_parser->reparse(index); //reparse the funcion
if ( m_parser->errmsg() != 0)
{
......@@ -98,7 +106,11 @@ void KEditPolar::accept()
}
}
else
index = m_parser->addfkt(functionItem() );
{
m_parser->fixFunctionName(f_str);
f_str.prepend("r");
index = m_parser->addfkt(f_str );
}
if( index == -1 )
{
......@@ -109,7 +121,7 @@ void KEditPolar::accept()
return;
}
XParser::FktExt tmp_fktext; //all settings are saved here until we know that no errors have appeared
tmp_fktext.extstr = functionItem();
tmp_fktext.extstr = f_str;
if( checkBoxHide->isChecked() )
tmp_fktext.f_mode = 0;
......@@ -167,6 +179,7 @@ void KEditPolar::accept()
tmp_fktext.k_anz=0;
m_parser->fktext[index] = tmp_fktext;
kLineEditYFunction->setText(f_str);
// call inherited method
......@@ -175,7 +188,7 @@ void KEditPolar::accept()
const QString KEditPolar::functionItem()
{
return "r" + kLineEditYFunction->text();
return kLineEditYFunction->text();
}
void KEditPolar::slotHelp()
......
......@@ -98,6 +98,7 @@ void KMinMax::init(char m)
cmdFind->setText("&Draw");
}
min->setFocus();
updateFunctions();
}
......
<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>QMinMax</class>
<widget class="QDialog">
<property name="name">
......@@ -26,6 +26,9 @@
<property name="text">
<string>&amp;Find</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
<widget class="QFrame" row="0" column="0" rowspan="1" colspan="2">
<property name="name">
......
......@@ -180,14 +180,14 @@ double XParser::a2fkt( int ix, double x, double h )
return ( ufkt[ ix ].fkt( x + h + h ) - 2 * ufkt[ ix ].fkt( x + h ) + ufkt[ ix ].fkt( x ) ) / h / h;
}
char XParser::findFunctionName()
char XParser::findFunctionName(int const index)
{
char function_name ='f';
for (bool ok=true; function_name< 'x';function_name++)
{
for ( int i = 0; i < ufanz; i++ )
{
if (fktext[ i ].extstr.at(0) == function_name ) //check if
if (fktext[ i ].extstr.at(0) == function_name && i!=index) //check if
if (fktext[ i ].extstr.at(1) == '(' ) //and the function name is one letter
ok = false;
}
......@@ -199,14 +199,14 @@ char XParser::findFunctionName()
}
return 'e'; //this should never happen, because the limit of 10 functions
}
void XParser::fixFunctionName( QString &str)
void XParser::fixFunctionName( QString &str, int const index)
{
int p1=str.find('(');
int p2=str.find(')');
if ( p1==-1 || !str.at(p1+1).isLetter() || p2==-1 || str.at(p2+1) != '=')
{
char function_name = findFunctionName();
char function_name = findFunctionName(index);
str.prepend("(x)=");
str.prepend(function_name);
}
......
......@@ -63,9 +63,8 @@ public:
/// Line width default
int linewidth0;
///Return an unused functionname
char findFunctionName();
void fixFunctionName(QString &);
///Return an unused function name
void fixFunctionName(QString &, int const=-1);
/// Extended attributes are encapulated in this structure.
struct FktExt
......@@ -99,6 +98,9 @@ public:
// TODO double slider_min, slider_max; ///< extreme values of the slider
}
*fktext;
private:
char findFunctionName(int const);
};
#endif //xparser_included
......
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