Commit 2068d6b6 authored by Matthias Messmer's avatar Matthias Messmer

parametric plot editor implemented.

now the pair of definition equations are displayed as 1 list item separated by ";"

svn path=/trunk/kdeedu/kmplot/; revision=296399
parent 9bcf7bc8
......@@ -37,6 +37,8 @@
#include "MainDlg.h"
#include "keditfunction.h"
#include <kdebug.h>
#define Inherited FktDlgData
FktDlg::FktDlg( QWidget* parent, const char* name ) : Inherited( parent, name )
......@@ -56,75 +58,75 @@ FktDlg::~FktDlg()
// Slots
void FktDlg::onnew()
{
int ix;
char c0;
QString fname, fstr, str;
// fstr = le_fktstr->text();
if ( !fstr.isEmpty() )
{
// left from semicolon is function equation
int i = fstr.find( ';' );
if ( i == -1 )
str = fstr;
else
str = fstr.left( i );
// test the function equation syntax
ix = ps.addfkt( str );
if ( ix == -1 )
{
ps.errmsg();
errflg = 1;
return ;
}
// handle the extensions
ps.fktext[ ix ].extstr = fstr;
// test the extension syntax
if ( ps.getext( ix ) == -1 )
{
errflg = 1;
return ;
}
// handle parametric functions: xf(t), yf(t)
if ( ( c0 = fstr[ 0 ].latin1() ) == 'x' )
{
ps.getfkt( ix, fname, str );
fname[ 0 ] = 'y';
if ( ps.getfix( fname ) == -1 )
{
int p;
lb_fktliste->insertItem( fstr );
// fktidx.append( lb_fktliste->currentItem() );
p = fstr.find( '=' );
fstr = fstr.left( p + 1 );
fstr[ 0 ] = 'y';
/* le_fktstr->setText( fstr );
le_fktstr->setFocus();
le_fktstr->deselect();
*/ return ;
}
}
else if ( c0 == 'y' )
{
if ( ps.getfkt( ix, fname, str ) != -1 )
{
fname[ 0 ] = 'x';
ix = ps.getfix( fname );
}
}
lb_fktliste->insertItem( fstr );
// le_fktstr->clear();
}
errflg = 0;
updateView();
}
// void FktDlg::onnew()
// {
// int ix;
// char c0;
// QString fname, fstr, str;
//
// // fstr = le_fktstr->text();
// if ( !fstr.isEmpty() )
// {
// // left from semicolon is function equation
// int i = fstr.find( ';' );
//
// if ( i == -1 )
// str = fstr;
// else
// str = fstr.left( i );
//
// // test the function equation syntax
// ix = ps.addfkt( str );
// if ( ix == -1 )
// {
// ps.errmsg();
// errflg = 1;
// return ;
// }
//
// // handle the extensions
// ps.fktext[ ix ].extstr = fstr;
// // test the extension syntax
// if ( ps.getext( ix ) == -1 )
// {
// errflg = 1;
// return ;
// }
//
// // handle parametric functions: xf(t), yf(t)
// if ( ( c0 = fstr[ 0 ].latin1() ) == 'x' )
// {
// ps.getfkt( ix, fname, str );
// fname[ 0 ] = 'y';
// if ( ps.getfix( fname ) == -1 )
// {
// int p;
//
// lb_fktliste->insertItem( fstr );
// // fktidx.append( lb_fktliste->currentItem() );
// p = fstr.find( '=' );
// fstr = fstr.left( p + 1 );
// fstr[ 0 ] = 'y';
// /* le_fktstr->setText( fstr );
// le_fktstr->setFocus();
// le_fktstr->deselect();
// */ return ;
// }
// }
// else if ( c0 == 'y' )
// {
// if ( ps.getfkt( ix, fname, str ) != -1 )
// {
// fname[ 0 ] = 'x';
// ix = ps.getfix( fname );
// }
// }
// lb_fktliste->insertItem( fstr );
// // le_fktstr->clear();
// }
// errflg = 0;
// updateView();
// }
void FktDlg::ondelete()
{
......@@ -143,26 +145,25 @@ void FktDlg::ondelete()
void FktDlg::onedit()
{
int num = lb_fktliste->currentItem();
int index = getIx( lb_fktliste->text( num ) );
int index = getIx( lb_fktliste->text( num ).section( ";", 0, 0) );
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
QString definition = ps.fktext[ index ].extstr;
// find out the function type
char prefix = definition.at(0).latin1();
char prefix = ps.fktext[ index ].extstr.at(0).latin1();
switch( prefix )
{
case 'r':
onEditPolar( index, num );
break;
case 'x':
case 'y':
onEditParametric( index, num );
onEditParametric( index, getIx( lb_fktliste->text( num ).section( ";", 1, 1) ), num );
break;
default:
onEditFunction( index, num );
}
updateView();
}
int FktDlg::getIx( const QString f_str )
......@@ -203,14 +204,15 @@ void FktDlg::onEditFunction( int index, int num )
}
}
void FktDlg::onEditParametric( int index, int num )
void FktDlg::onEditParametric( int x_index, int y_index, int num )
{
if( !editFunction ) editFunction = new KEditFunction( &ps, this );
editFunction->initDialog( KEditFunction::Parametric, index );
editFunction->initDialog( KEditFunction::Parametric, x_index, y_index );
if( editFunction->exec() == QDialog::Accepted )
{
lb_fktliste->insertItem( editFunction->xFunction() );
lb_fktliste->insertItem( editFunction->yFunction() );
if( x_index == -1 )
lb_fktliste->insertItem( editFunction->xFunction() + ";" + editFunction->yFunction() );
else lb_fktliste->changeItem( editFunction->xFunction() + ";" + editFunction->yFunction(), num );
}
}
......@@ -235,9 +237,16 @@ void FktDlg::fillList()
// adding all yet added functions
for ( index = 0; index < ps.ufanz; ++index )
{
if ( ps.getfkt( index, fname, fstr ) == -1 )
continue;
lb_fktliste->insertItem( ps.fktext[ index ].extstr );
if ( ps.getfkt( index, fname, fstr ) == -1 ) continue;
if( fname[0] == 'y' ) continue;
if( fname[0] == 'x' )
{
QString y_name( fname );
y_name[0] = 'y';
int y_index = ps.getfix( y_name );
if( y_index == -1 ) continue;
lb_fktliste->insertItem( ps.fktext[ index ].extstr + ";" + ps.fktext[ y_index ].extstr );
}
else lb_fktliste->insertItem( ps.fktext[ index ].extstr );
}
}
......@@ -68,12 +68,12 @@ public:
protected slots:
void ondelete();
void onedit();
void onnew();
// void onnew();
void onHasSelection();
// edit the function, index: parser index, num: listbox index
void onEditFunction( int index = -1, int num = -1 );
void onEditParametric( int index = -1, int num = -1 );
void onEditParametric( int x_index = -1, int y_index = -1, int num = -1 );
void onEditPolar( int index = -1, int num = -1 );
private:
......
......@@ -48,10 +48,11 @@ KEditFunction::KEditFunction( XParser* parser, QWidget* parent, const char* name
/**
* Fill the dialog's widgets with the properties of the parser function number index.
*/
void KEditFunction::initDialog( const FunctionType t, int index )
void KEditFunction::initDialog( const FunctionType t, int index, int y_index )
{
m_type = t;
m_index = index;
m_y_index = y_index;
setVisibleWidgets();
if( m_index == -1 ) clearWidgets();
else setWidgets();
......@@ -135,6 +136,10 @@ void KEditFunction::setWidgets()
kLineEditYFunction->setText( expression );
break;
case Parametric:
kLineEditName->setText( name );
kLineEditXFunction->setText( expression );
splitEquation( m_parser->fktext[ m_y_index ].extstr, name, expression );
kLineEditYFunction->setText( expression );
break;
}
checkBoxHide->setChecked( m_parser->fktext[ m_index ].f_mode == 0 );
......@@ -152,6 +157,11 @@ void KEditFunction::accept()
m_parser->delfkt( m_index );
m_index = -1;
}
if( m_y_index != -1 )
{
m_parser->delfkt( m_y_index );
m_y_index = -1;
}
// find a name not allready used
if( kLineEditName->text().isEmpty() )
......
......@@ -39,7 +39,7 @@ class KEditFunction : public QEditFunction
enum FunctionType { Function, Parametric, Polar };
void initDialog( const FunctionType t, int index = -1 );
void initDialog( const FunctionType t, int index = -1, int y_index = -1 );
// void setFunction( int index );
QString xFunction();
QString yFunction();
......@@ -52,7 +52,7 @@ class KEditFunction : public QEditFunction
void splitEquation( const QString equation, QString &name, QString &expression );
FunctionType m_type;
XParser* m_parser;
int m_index;
int m_index, m_y_index;
protected:
virtual void accept();
......
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