Commit 09a9cf6b authored by Matthias Messmer's avatar Matthias Messmer

function name is calculated automatically if leaving blanc

svn path=/trunk/kdeedu/kmplot/; revision=295868
parent 1929bb92
......@@ -136,12 +136,17 @@ void KEditFunction::setWidgets()
void KEditFunction::accept()
{
// if we are editing an existing function, first delete the old one
if( m_index != -1 )
{
m_parser->delfkt( m_index );
m_index = -1;
}
// find a name not allready used
if( kLineEditName->text().isEmpty() )
kLineEditName->setText( newName() );
int index = m_parser->addfkt( yFunction() );
if( index == -1 )
{
......@@ -191,6 +196,33 @@ void KEditFunction::accept()
QEditFunction::accept();
}
QString KEditFunction::newName()
{
int i = 0;
QString name;
// prepend the correct prefix
switch( m_type )
{
case Function:
name = "f%1";
break;
case Parametric:
name = "xf%1";
break;
case Polar:
name = "rf%1";
}
do
{
i++;
} while( m_parser->getfix( name.arg( i ) ) != -1 );
// cut of prefix again, will be added later again
if( m_type == Parametric || m_type == Polar )
name = name.right( name.length()-1 );
return name.arg( i );
}
QString KEditFunction::xFunction()
{
return "x" + kLineEditName->text() + "(t)=" + kLineEditXFunction->text();
......
......@@ -48,6 +48,7 @@ class KEditFunction : public QEditFunction
void setVisibleWidgets();
void clearWidgets();
void setWidgets();
QString newName();
void splitEquation( const QString equation, QString &name, QString &expression );
FunctionType m_type;
XParser* m_parser;
......
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>282</width>
<height>484</height>
<width>293</width>
<height>486</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -71,7 +71,8 @@
<string>enter the expression</string>
</property>
<property name="whatsThis" stdset="0">
<string>Enter an expression for the function.</string>
<string>Enter an expression for the function. The dummy variable is t.
Example: t^2</string>
</property>
</widget>
<widget class="KLineEdit" row="0" column="1">
......@@ -85,7 +86,8 @@
<string>name of the function</string>
</property>
<property name="whatsThis" stdset="0">
<string>Enter the name of the function.</string>
<string>Enter the name of the function.
The name of a function must be unique. If you leave this line empty KmPlot will set a default name. You can change it later.</string>
</property>
</widget>
<widget class="QLayoutWidget" row="2" column="0">
......
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