Commit b8d95fd9 authored by Fredrik Edemar's avatar Fredrik Edemar

* Make it possible to move/copy polar and parametric functions to other KmPlot instances.

* Cleaned some code.

svn path=/trunk/kdeedu/kmplot/; revision=369690
parent 4903fec0
......@@ -247,15 +247,7 @@ void FktDlg::slotCopyFunction()
return;
}
QString const fstr = lb_fktliste->text(num);
if( fstr.at(0) == 'x' )
{
int const id = getParamId( lb_fktliste->text( num ));
if ( !m_view->parser()->sendFunction(id) )
return;
m_view->parser()->sendFunction(id+1);
}
else
m_view->parser()->sendFunction(getId(fstr));
m_view->parser()->sendFunction(getId(fstr));
}
void FktDlg::slotMoveFunction()
......@@ -267,18 +259,7 @@ void FktDlg::slotMoveFunction()
return;
}
QString const fstr = lb_fktliste->text(num);
if( fstr.at(0) == 'x' )
{
int const id = getParamId( lb_fktliste->text( num ));
if ( !m_view->parser()->sendFunction(id) )
return;
if ( m_view->parser()->sendFunction(id+1) )
return;
}
else
if ( !m_view->parser()->sendFunction(getId( lb_fktliste->text( lb_fktliste->currentItem())) ) )
return;
if ( !m_view->parser()->sendFunction(getId( lb_fktliste->text( lb_fktliste->currentItem())) ) )
return;
slotDelete();
}
......@@ -525,7 +525,10 @@ void MainDlg::slotQuickEdit(const QString& tmp_f_str )
{
//creates a valid name for the function if the user has forgotten that
QString f_str( tmp_f_str );
view->parser()->fixFunctionName(f_str);
if (f_str.at(0)=='r')
view->parser()->fixFunctionName(f_str, XParser::Polar);
else
view->parser()->fixFunctionName(f_str);
if ( f_str.at(0)== 'x' || f_str.at(0)== 'y')
{
KMessageBox::error( m_parent, i18n("Parametric functions must be definied in the \"New Parametric Plot\"-dialog which you can find in the menubar"));
......
......@@ -101,10 +101,14 @@ void KEditParametric::accept()
// find a name not already used
if( kLineEditName->text().isEmpty() )
kLineEditName->setText( newName() );
{
QString fname;
m_parser->fixFunctionName(fname, XParser::ParametricX);
int const pos = fname.find('(');
kLineEditName->setText(fname.mid(1,pos-1));
}
Ufkt tmp_ufkt;
tmp_ufkt.f_mode = !checkBoxHide->isChecked();
if( checkBoxRange->isChecked() )
......@@ -214,7 +218,7 @@ void KEditParametric::accept()
added_ufkt->use_slider = tmp_ufkt.use_slider;
added_ufkt = 0;
if( m_y_id != -1 ) //when editing a function:
if( m_y_id != -1 ) //when editing a function:
{
added_ufkt = &m_parser->ufkt[m_parser->ixValue(m_y_id)];
QString old_fstr = added_ufkt->fstr;
......@@ -234,7 +238,7 @@ void KEditParametric::accept()
else
{
int const id = m_parser->addfkt( yFunction() );
if( id == -1 )
if( id == -1 )
{
m_parser->parserError();
raise();
......@@ -276,25 +280,7 @@ void KEditParametric::accept()
// call inherited method
QEditParametric::accept(); //update the function name in FktDlg
}
QString KEditParametric::newName()
{
int i = 0;
QString name;
// prepend the correct prefix
name = "xf%1";
/*do
{
i++;
}
while( m_parser->getfix( name.arg( i ) ) != -1 );
*/
// cut off prefix again, will be added later
name = name.right( name.length()-1 );
return name.arg( i );
}
QString KEditParametric::xFunction()
{
return "x" + kLineEditName->text() + "(t)=" + kLineEditXFunction->text();
......@@ -303,7 +289,7 @@ QString KEditParametric::xFunction()
void KEditParametric::splitEquation( const QString equation, QString &name, QString &expression )
{
int start = 0;
if( equation[ 0 ] == 'r' || equation[ 0 ] == 'x' || equation[ 0 ] == 'y' ) start++;
if( equation[ 0 ] == 'x' || equation[ 0 ] == 'y' ) start++;
int length = equation.find( '(' ) - start;
name = equation.mid( start, length );
......
......@@ -56,9 +56,7 @@ class KEditParametric : public QEditParametric
/// Returns the well formed function equation
QString xFunction();
/// Returns the well formed function equation
QString yFunction();
/// Returns a unique functionname, if the name edit line was left empty.
QString newName();
QString yFunction();
/// extract function \a name and \a expression from a given \a equation
void splitEquation( const QString equation, QString &name, QString &expression );
/// Pointer to the parser instance.
......
......@@ -86,7 +86,7 @@ void KEditPolar::setWidgets()
void KEditPolar::accept()
{
QString f_str = kLineEditYFunction->text();
QString f_str = "r" + kLineEditYFunction->text();
if ( m_id!=-1 )
m_parser->fixFunctionName(f_str, XParser::Polar, m_id);
......@@ -199,7 +199,6 @@ void KEditPolar::accept()
added_ufkt->integral_color = tmp_ufkt.integral_color;
added_ufkt->parameters = tmp_ufkt.parameters;
added_ufkt->use_slider = tmp_ufkt.use_slider;
//added_ufkt->k_liste = tmp_ufkt.k_liste;
kLineEditYFunction->setText(f_str); //update the function name in FktDlg
// call inherited method
......
......@@ -144,7 +144,7 @@ void XParser::findFunctionName(QString &function_name, int const id, int const t
{
char last_character;
int pos;
if ( type == XParser::Polar)
if ( type == XParser::Polar || type == XParser::ParametricX || type == XParser::ParametricY)
pos=1;
else
pos=0;
......@@ -178,26 +178,36 @@ void XParser::fixFunctionName( QString &str, int const type, int const id)
{
int const p1=str.find('(');
int const p2=str.find(')');
if( p1>0)
if( p1>0 && str.at(p2+1)=='=')
{
QString const fname = str.left(p1);
for ( QValueVector<Ufkt>::iterator it = ufkt.begin(); it!=ufkt.end(); ++it )
if (it->fname == fname)
{
str = str.mid(p1,str.length()-1);
QString function_name = "f";
QString function_name;
if ( type == XParser::Polar )
function_name = "rf";
else if ( type == XParser::ParametricX )
function_name = "x";
else if ( type == XParser::ParametricY )
function_name = "y";
else
function_name = "f";
findFunctionName(function_name, id, type);
str.prepend( function_name );
return;
}
}
if ( p1==-1 || !str.at(p1+1).isLetter() || p2==-1 || str.at(p2+1 )!= '=')
else if ( p1==-1 || !str.at(p1+1).isLetter() || p2==-1 || str.at(p2+1 )!= '=')
{
QString function_name;
if ( type == XParser::Polar )
function_name = "rf";
else if ( type == XParser::ParametricX )
function_name = "xf";
else if ( type == XParser::ParametricY )
function_name = "yf";
else
function_name = "f";
str.prepend("(x)=");
......@@ -646,7 +656,24 @@ int XParser::addFunction(const QString &f_str)
bool XParser::addFunction(const QString &extstr, bool f_mode, bool f1_mode, bool f2_mode, bool integral_mode, bool integral_use_precision, int linewidth, int f1_linewidth, int f2_linewidth, int integral_linewidth, const QString &str_dmin, const QString &str_dmax, const QString &str_startx, const QString &str_starty, double integral_precision, QRgb color, QRgb f1_color, QRgb f2_color, QRgb integral_color, QStringList str_parameter, bool use_slider)
{
QString fstr(extstr);
fixFunctionName(fstr);
switch ( fstr.at(0).latin1() )
{
case 'r':
{
fixFunctionName(fstr, XParser::Polar);
kdDebug() << "Hit?" << endl;
break;
}
case 'x':
fixFunctionName(fstr, XParser::ParametricX);
break;
case 'y':
fixFunctionName(fstr, XParser::ParametricY);
break;
default:
fixFunctionName(fstr, XParser::Function);
break;
}
int const id = addfkt( fstr );
if ( id==-1 )
return false;
......@@ -708,7 +735,7 @@ bool XParser::setFunctionExpression(const QString &f_str, uint id)
return true;
}
bool XParser::sendFunction(int id)
bool XParser::sendFunction(int id, const QString &dcopclient_target)
{
QCStringList cstr_list = kapp->dcopClient()->registeredApplications();
QStringList str_list;
......@@ -721,28 +748,27 @@ bool XParser::sendFunction(int id)
return false;
}
//Ufkt *ufkt = &->ufkt[->ixValue(getId( lb_fktliste->text( lb_fktliste->currentItem() )))];
Ufkt *item = &ufkt[ixValue(id)];
kdDebug() << "Snder " << item->fname.latin1() << endl;
QString str_result;
if (item->fname.at(0) != 'y')
if ( dcopclient_target.isEmpty() && item->fname.at(0) == 'y' )
return false;
else if ( dcopclient_target.isEmpty() )
{
bool ok;
str_result = KInputDialog::getItem(i18n("kmplot"), i18n("Choose which KmPlot instance\nyou want to copy the function to:"), str_list, 0, false, &ok);
if (!ok)
return false;
if (item->fname.at(0) == 'x')
m_tmpdcopclient = str_result;
return false;
}
else
str_result = m_tmpdcopclient;
str_result = dcopclient_target;
QByteArray parameters;
QDataStream arg( parameters, IO_WriteOnly);
QStringList str_parameters;
for ( QValueList<ParameterValueItem>::Iterator it = item->parameters.begin(); it != item->parameters.end(); ++it )
str_parameters.append( (*it).expression);
str_parameters.append( (*it).expression);
arg << item->extstr << item->f_mode << item->f1_mode << item->f2_mode << item->integral_mode << item->integral_use_precision << item->linewidth << item->f1_linewidth << item->f2_linewidth << item->integral_linewidth << item->str_dmin << item->str_dmax << item->str_startx << item->str_starty << item->integral_precision << item->color << item->f1_color << item->f2_color << item->integral_color << str_parameters << item->use_slider;
QByteArray replay_data;
QCString replay_type;
......@@ -763,5 +789,9 @@ bool XParser::sendFunction(int id)
}
kapp->dcopClient()->send(str_result.utf8(), "View","drawPlot()",QByteArray() ); //update the other window
return true;
if (item->fname.at(0) == 'x') // a parametric function
return sendFunction(id+1, str_result);
else
return true;
}
......@@ -57,7 +57,7 @@ public:
int linewidth0;
QRgb defaultColor(int function);
enum { Function, Polar, Parametric }; ///types of functions
enum { Function, Polar, ParametricX, ParametricY }; ///types of functions
///Returns an unused function name if it is needed
void fixFunctionName(QString &, int const = XParser::Function , int const=-1);
......@@ -70,7 +70,7 @@ public:
int getext( Ufkt * );
/// Send a function to an other instance of Kmplot. Returns true if it success, otherwise false
bool sendFunction(int id);
bool sendFunction(int id, const QString &dcopclient_target="");
/// Functions for the DCOP interface:
......@@ -140,8 +140,6 @@ private:
/// finds a free function name
void findFunctionName(QString &, int const, int const);
/// used when sending parametric functions
QString m_tmpdcopclient;
/// indicates if the widget is changed
bool &m_modified;
};
......
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