Commit 86c6f911 authored by Fredrik Edemar's avatar Fredrik Edemar

Add checkboxes to the the function list so that the user can show/hide a function.

svn path=/trunk/kdeedu/kmplot/; revision=399216
parent db05c2f0
......@@ -29,10 +29,13 @@
// KDE includes
#include <kapplication.h>
#include <klistview.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <qcstring.h>
#include <qcursor.h>
#include <qheader.h>
// locale includes
#include "FktDlg.h"
......@@ -50,6 +53,13 @@ FktDlg::FktDlg( QWidget* parent, View *view ) : FktDlgData( parent, "editPlots"
{
connect( cmdCopyFunction, SIGNAL( clicked() ), this, SLOT( slotCopyFunction()) );
connect( cmdMoveFunction, SIGNAL( clicked() ), this, SLOT( slotMoveFunction()) );
connect( lb_fktliste, SIGNAL( doubleClicked(QListViewItem *, const QPoint &, int)), this, SLOT(lb_fktliste_doubleClicked(QListViewItem *, const QPoint &, int)) );
connect( lb_fktliste, SIGNAL( clicked(QListViewItem *)), this, SLOT(lb_fktliste_clicked(QListViewItem *)));
connect( lb_fktliste, SIGNAL( spacePressed(QListViewItem *)), this, SLOT(lb_fktliste_spacePressed(QListViewItem *)));
lb_fktliste->addColumn( "" );
lb_fktliste->header()->hide();
lb_fktliste->setResizeMode( QListView::LastColumn );
}
FktDlg::~FktDlg()
......@@ -58,58 +68,88 @@ FktDlg::~FktDlg()
void FktDlg::slotDelete()
{
if ( lb_fktliste->currentItem()== -1)
{
PushButtonDel->setEnabled(false);
if ( lb_fktliste->currentItem() == 0)
return;
}
int num;
if ( ( num = lb_fktliste->currentItem() ) == -1 ) return ;
if( lb_fktliste->text( num )[0] == 'x' )
QCheckListItem *currentItem = dynamic_cast<QCheckListItem *>(lb_fktliste->currentItem());
if( currentItem->text()[0] == 'x' )
{
// Delete pair of parametric function
int const id = getParamId( lb_fktliste->text( num ));
if ( id == -1)
return;
if ( m_view->parser()->delfkt(id))
return;
// Delete pair of parametric function
int const id = getParamId( currentItem->text());
if ( id == -1)
return;
if ( !m_view->parser()->delfkt(id))
return;
}
else
{
// only one function to be deleted
if (!m_view->parser()->delfkt( getId( lb_fktliste->text( num )) ) )
return;
// only one function to be deleted
if (!m_view->parser()->delfkt( getId( currentItem->text()) ) )
return;
}
lb_fktliste->removeItem( num );
lb_fktliste->takeItem( currentItem );
changed = true;
updateView();
if ( lb_fktliste->childCount()==0 )
PushButtonDel->setEnabled(false);
}
void FktDlg::lb_fktliste_doubleClicked( QListViewItem *, const QPoint &, int )
{
if ( mapFromGlobal(QCursor::pos()).x() <= 40 )
return;
slotEdit();
}
void FktDlg::lb_fktliste_spacePressed( QListViewItem *item)
{
if ( !item )
return;
QCheckListItem *currentItem = dynamic_cast<QCheckListItem *>(item);
int id;
if ( currentItem->text()[0] == 'x' )
id = getParamId(currentItem->text());
else
id = getId(currentItem->text());
Ufkt *function = &m_view->parser()->ufkt[ m_view->parser()->ixValue(id) ];
if ( id==-1 )
return;
function->f_mode=currentItem->isOn();
updateView();
}
void FktDlg::lb_fktliste_clicked( QListViewItem * item )
{
if ( mapFromGlobal(QCursor::pos()).x() > 40 )
return;
lb_fktliste_spacePressed(item);
}
void FktDlg::slotEdit()
{
if ( lb_fktliste->currentItem()==-1 )
QCheckListItem *currentItem = dynamic_cast<QCheckListItem *>(lb_fktliste->currentItem());
if ( currentItem == 0 )
{
PushButtonEdit->setEnabled(false);
return;
}
int const num = lb_fktliste->currentItem();
int const id = getId( lb_fktliste->currentText().section( ";", 0, 0) ) ;
int const id = getId( currentItem->text().section( ";", 0, 0) ) ;
// find out the function type
char const prefix = m_view->parser()->ufkt[ m_view->parser()->ixValue(id) ].fstr.at(0).latin1();
if ( prefix == 'r')
slotEditPolar( id, num );
slotEditPolar( id );
else if ( prefix == 'x')
slotEditParametric( id, m_view->parser()->ixValue(getId( lb_fktliste->text( num ).section( ";", 1, 1) )), num );
slotEditParametric( id, m_view->parser()->ixValue(getId( currentItem->text().section( ";", 1, 1) )));
else
slotEditFunction( id, num );
slotEditFunction( id );
}
int FktDlg::getId( const QString &f_str )
{
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if ( it->fstr == f_str )
return it->id;
......@@ -120,71 +160,100 @@ int FktDlg::getId( const QString &f_str )
int FktDlg::getParamId( const QString &f_str)
{
QString const fname = f_str.section( "(", 0, 0 );
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if ( it->fname == fname )
return it->id;
}
return -1;
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if ( it->fname == fname )
return it->id;
}
return -1;
}
void FktDlg::updateView()
{
//( ( MainDlg* )parentWidget() ) ->view->drawPlot();
m_view->drawPlot();
}
void FktDlg::slotHasSelection()
{
bool const has_selection = !( lb_fktliste->currentItem() == -1 );
bool const has_selection = !( lb_fktliste->currentItem() == 0 );
PushButtonEdit->setEnabled( has_selection );
PushButtonDel->setEnabled( has_selection );
cmdCopyFunction->setEnabled( has_selection );
cmdMoveFunction->setEnabled( has_selection );
}
void FktDlg::slotEditFunction( int id, int num )
void FktDlg::slotEditFunction( int id )
{
EditFunction* editFunction = new EditFunction( m_view->parser(), this );
if ( id==-1&&num==-1) editFunction->setCaption(i18n( "New Function Plot" ));
if ( id==-1 ) editFunction->setCaption(i18n( "New Function Plot" ));
else editFunction->setCaption(i18n( "Edit Function Plot" ));
editFunction->initDialog( id );
if( editFunction->exec() == QDialog::Accepted )
{
if( id == -1 ) lb_fktliste->insertItem( editFunction->functionItem() ); //a new function
else lb_fktliste->changeItem( editFunction->functionItem(), num ); //changed a function
Ufkt *function = editFunction->functionItem();
QCheckListItem *item;
if( id == -1 ) //a new function
item = new QCheckListItem(lb_fktliste, function->fstr, QCheckListItem::CheckBox); //a new function
else //change a function
{
item = dynamic_cast<QCheckListItem *>(lb_fktliste->currentItem());
item->setText(0, function->fstr );
}
item->setOn(function->f_mode);
lb_fktliste->sort();
changed = true;
changed = true;
updateView();
}
}
void FktDlg::slotEditParametric( int x_id, int y_id, int num )
void FktDlg::slotEditParametric( int x_id, int y_id)
{
KEditParametric* editParametric = new KEditParametric( m_view->parser(), this );
if ( x_id==-1&&y_id==-1&&num==-1) editParametric->setCaption(i18n( "New Parametric Plot" ));
if ( x_id==-1 && y_id==-1)
editParametric->setCaption(i18n( "New Parametric Plot" ));
editParametric->initDialog( x_id, y_id );
if( editParametric->exec() == QDialog::Accepted )
{
if( x_id == -1 ) lb_fktliste->insertItem( editParametric->functionItem() ); //a new function
else lb_fktliste->changeItem( editParametric->functionItem(), num ); //changed a function
Ufkt *function_y = editParametric->functionItem();
Ufkt *function_x = &m_view->parser()->ufkt[m_view->parser()->ixValue(function_y->id - 1)]; //get the x-function
QCheckListItem *item;
if( x_id == -1 ) //a new function
{
item = new QCheckListItem(lb_fktliste, function_x->fstr+";"+function_y->fstr, QCheckListItem::CheckBox);
}
else //change a function
{
item = dynamic_cast<QCheckListItem *>(lb_fktliste->currentItem());
item->setText(0, function_x->fstr+";"+function_y->fstr );
}
item->setOn(function_y->f_mode);
lb_fktliste->sort();
changed = true;
changed = true;
updateView();
}
}
void FktDlg::slotEditPolar( int id, int num )
void FktDlg::slotEditPolar( int id )
{
KEditPolar* editPolar = new KEditPolar( m_view->parser(), this );
if ( id==-1&&num==-1) editPolar->setCaption(i18n( "New Polar Plot" ));
if ( id==-1) editPolar->setCaption(i18n( "New Polar Plot" ));
editPolar->initDialog( id );
if( editPolar->exec() == QDialog::Accepted )
{
if( id == -1 ) lb_fktliste->insertItem( editPolar->functionItem() ); //a new function
else lb_fktliste->changeItem( editPolar->functionItem(), num ); //changed a function
Ufkt *function = editPolar->functionItem();
QCheckListItem *item;
if( id == -1 ) // a new function
{
item = new QCheckListItem(lb_fktliste, function->fstr, QCheckListItem::CheckBox);
}
else //change a function
{
item = dynamic_cast<QCheckListItem *>(lb_fktliste->currentItem());
item->setText(0, function->fstr );
}
item->setOn(function->f_mode);
lb_fktliste->sort();
changed = true;
changed = true;
updateView();
}
}
......@@ -208,19 +277,22 @@ void FktDlg::getPlots()
{
lb_fktliste->clear();
// adding all yet added functions
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
// adding all yet added functions
for( QValueVector<Ufkt>::iterator it = m_view->parser()->ufkt.begin(); it != m_view->parser()->ufkt.end(); ++it)
{
if( it->fname.isEmpty() || it->fstr[0] == 'y' ) continue;
if( it->fname.isEmpty() || it->fstr[0] == 'y' ) continue;
QCheckListItem *item;
if( it->fstr[0] == 'x' )
{
QString y = it->fstr;
++it;
lb_fktliste->insertItem( y + ";" + it->fstr );
QString y = it->fstr;
++it;
item = new QCheckListItem( lb_fktliste, y + ";" + it->fstr, QCheckListItem::CheckBox );
}
else lb_fktliste->insertItem( it->fstr );
else
item = new QCheckListItem(lb_fktliste, it->fstr, QCheckListItem::CheckBox);
item->setOn(it->f_mode);
}
lb_fktliste->sort();
lb_fktliste->sort();
}
void FktDlg::slotHelp()
......@@ -240,26 +312,26 @@ void FktDlg::showEvent ( QShowEvent * )
void FktDlg::slotCopyFunction()
{
int num;
if ( ( num = lb_fktliste->currentItem() )== -1)
if ( lb_fktliste->currentItem() == 0)
{
cmdCopyFunction->setEnabled(false);
return;
}
QString const fstr = lb_fktliste->text(num);
QCheckListItem *currentItem = dynamic_cast<QCheckListItem *>(lb_fktliste->currentItem());
QString const fstr = currentItem->text();
m_view->parser()->sendFunction(getId(fstr));
}
void FktDlg::slotMoveFunction()
{
int num;
if ( ( num = lb_fktliste->currentItem() )== -1)
if ( lb_fktliste->currentItem() == 0)
{
cmdCopyFunction->setEnabled(false);
return;
}
QString const fstr = lb_fktliste->text(num);
if ( !m_view->parser()->sendFunction(getId( lb_fktliste->text( lb_fktliste->currentItem())) ) )
QCheckListItem *currentItem = dynamic_cast<QCheckListItem *>(lb_fktliste->currentItem());
QString const fstr = currentItem->text();
if ( !m_view->parser()->sendFunction(getId( currentItem->text()) ) )
return;
slotDelete();
}
......@@ -72,22 +72,25 @@ protected slots:
void slotEdit();
/// Enables/disables actions if the list has a/no selection.
void slotHasSelection();
void lb_fktliste_doubleClicked(QListViewItem *, const QPoint &, int);
void lb_fktliste_clicked(QListViewItem * item);
void lb_fktliste_spacePressed(QListViewItem * item);
/// Edit a function plot.
/// @param index Function index of the parser instance.
/// @param num Listbox index
/// @see KEditFunction
void slotEditFunction( int id = -1, int num = -1 );
void slotEditFunction( int id = -1 );
/// Edit a parametric plot.
/// @param x_index, y_index Function index of the parser instance.
/// @param num Listbox index
/// @see KEditParametric
void slotEditParametric( int x_id = -1, int y_id = -1, int num = -1 );
void slotEditParametric( int x_id = -1, int y_id = -1 );
/// Edit a polar plot.
/// @param index Function index of the parser instance.
/// @param num Listbox index
/// @see KEditPolar
void slotEditPolar( int id = -1, int num = -1 );
void slotEditPolar( int id = -1 );
/// Edit a new function plot.
void slotNewFunction();
/// Edit a new parametric plot.
......
......@@ -108,7 +108,7 @@
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QListBox" row="0" column="0" rowspan="9" colspan="1">
<widget class="KListView" row="0" column="0" rowspan="9" colspan="1">
<property name="name">
<cstring>lb_fktliste</cstring>
</property>
......@@ -347,12 +347,6 @@
<receiver>FktDlgData</receiver>
<slot>slotDelete()</slot>
</connection>
<connection>
<sender>lb_fktliste</sender>
<signal>selected(int)</signal>
<receiver>FktDlgData</receiver>
<slot>slotEdit()</slot>
</connection>
<connection>
<sender>lb_fktliste</sender>
<signal>selectionChanged()</signal>
......
......@@ -73,6 +73,7 @@ EditFunction::EditFunction( XParser* parser, QWidget* parent, const char* name )
connect( editfunctionpage->useNoParameter, SIGNAL ( toggled(bool) ), this, SLOT( noParameter_toggled(bool) ) );
connect( editfunctionpage->customMinRange, SIGNAL ( toggled(bool) ), this, SLOT( customMinRange_toggled(bool) ) );
connect( editfunctionpage->customMaxRange, SIGNAL ( toggled(bool) ), this, SLOT( customMaxRange_toggled(bool) ) );
m_updatedfunction = 0;
}
void EditFunction::initDialog( int id )
......@@ -168,7 +169,7 @@ void EditFunction::setWidgets()
void EditFunction::accept()
{
QString f_str(functionItem() );
QString f_str( editfunctionpage->equation->text() );
if ( m_id!=-1 )
m_parser->fixFunctionName(f_str, XParser::Function, m_id);
......@@ -372,15 +373,15 @@ void EditFunction::accept()
added_ufkt->usecustomxmin = tmp_ufkt.usecustomxmin;
added_ufkt->usecustomxmax = tmp_ufkt.usecustomxmax;
editfunctionpage->equation->setText(f_str); //update the function name in FktDlg
m_updatedfunction = added_ufkt;
// call inherited method
KDialogBase::accept();
}
const QString EditFunction::functionItem()
Ufkt * EditFunction::functionItem()
{
return editfunctionpage->equation->text();
return m_updatedfunction;
}
void EditFunction::slotHelp()
......
......@@ -48,8 +48,8 @@ class EditFunction : public KDialogBase
virtual ~EditFunction() {};
/// Fill the dialog's widgets with the properties of the parser function number index.
void initDialog( int id = -1 );
/// Returns the well formed function equation for the listbox in FktDlg.
const QString functionItem();
/// Returns a pointer to the added/updated function
Ufkt *functionItem();
protected slots:
/// Overwrites the dialog's accept() method to make sure, that the user's input is valid.
......@@ -84,6 +84,8 @@ class EditFunction : public KDialogBase
EditFunctionPage* editfunctionpage;
EditDerivativesPage* editderivativespage;
EditIntegralPage* editintegralpage;
Ufkt *m_updatedfunction;
};
#endif
......@@ -46,6 +46,7 @@ KEditParametric::KEditParametric( XParser* parser, QWidget* parent, const char*
{
connect( customMinRange, SIGNAL ( toggled(bool) ), this, SLOT( customMinRange_toggled(bool) ) );
connect( customMaxRange, SIGNAL ( toggled(bool) ), this, SLOT( customMaxRange_toggled(bool) ) );
m_updatedfunction = 0;
}
void KEditParametric::initDialog( int x_id, int y_id)
......@@ -179,7 +180,6 @@ void KEditParametric::accept()
added_ufkt = &m_parser->ufkt[ix];
QString old_fstr = added_ufkt->fstr;
added_ufkt->fstr = xFunction();
added_ufkt->fstr = added_ufkt->fstr;
m_parser->reparse(added_ufkt); //reparse the funcion
if ( m_parser->parserError() != 0)
{
......@@ -239,7 +239,6 @@ void KEditParametric::accept()
added_ufkt = &m_parser->ufkt[m_parser->ixValue(m_y_id)];
QString old_fstr = added_ufkt->fstr;
added_ufkt->fstr = yFunction();
added_ufkt->fstr = added_ufkt->fstr;
m_parser->reparse(added_ufkt); //reparse the funcion
if ( m_parser->parserError() != 0) //when something went wrong:
{
......@@ -293,6 +292,7 @@ void KEditParametric::accept()
added_ufkt->use_slider = tmp_ufkt.use_slider;
added_ufkt->usecustomxmin = tmp_ufkt.usecustomxmin;
added_ufkt->usecustomxmax = tmp_ufkt.usecustomxmax;
m_updatedfunction = added_ufkt;
// call inherited method
......@@ -319,9 +319,9 @@ QString KEditParametric::yFunction()
return "y" + kLineEditName->text() + "(t)=" + kLineEditYFunction->text();
}
const QString KEditParametric::functionItem()
Ufkt * KEditParametric::functionItem()
{
return xFunction()+";"+yFunction();
return m_updatedfunction;
}
void KEditParametric::slotHelp()
......
......@@ -27,6 +27,7 @@
#define KEDITPARAMETRIC_H
#include "qeditparametric.h"
#include "xparser.h"
class View;
class XParser;
......@@ -45,8 +46,8 @@ class KEditParametric : public QEditParametric
/// Fill the dialog's widgets with the properties of the parser function number id.
void initDialog( int x_id = -1, int y_id = -1 );
/// Returns the well formed function equation for the listbox in FktDlg.
const QString functionItem();
/// Returns a pointer to the added/inserted y-function, or 0 if the user havn't pressed OK yet
Ufkt *functionItem();
private:
/// Clear alls widgets values
......@@ -73,6 +74,8 @@ class KEditParametric : public QEditParametric
void slotHelp();
void customMaxRange_toggled(bool);
void customMinRange_toggled(bool);
Ufkt *m_updatedfunction;
};
#endif
......@@ -47,6 +47,7 @@ KEditPolar::KEditPolar( XParser* parser, QWidget* parent, const char* name ) :
{
connect( customMinRange, SIGNAL ( toggled(bool) ), this, SLOT( customMinRange_toggled(bool) ) );
connect( customMaxRange, SIGNAL ( toggled(bool) ), this, SLOT( customMaxRange_toggled(bool) ) );
m_updatedfunction = 0;
}
void KEditPolar::initDialog( int id )
......@@ -216,14 +217,15 @@ void KEditPolar::accept()
added_ufkt->usecustomxmin = tmp_ufkt.usecustomxmin;
added_ufkt->usecustomxmax = tmp_ufkt.usecustomxmax;
kLineEditYFunction->setText(f_str); //update the function name in FktDlg
m_updatedfunction = added_ufkt;
// call inherited method
QEditPolar::accept();
}
const QString KEditPolar::functionItem()
Ufkt *KEditPolar::functionItem()
{
return kLineEditYFunction->text();
return m_updatedfunction;
}
void KEditPolar::slotHelp()
......
......@@ -27,6 +27,7 @@
#define KEDITPOLAR_H
#include "qeditpolar.h"
#include "xparser.h"
class View;
class XParser;
......@@ -45,8 +46,8 @@ class KEditPolar : public QEditPolar
///Fill the dialog widgets with the properties of the parser function number id.
void initDialog( int id = -1 );
/// Returns the well formed function equation for the listbox in FktDlg.
const QString functionItem();
/// Returns a pointer to the added/updated function
Ufkt * functionItem();
private:
/// Clear alls widgets values.
......@@ -65,6 +66,8 @@ class KEditPolar : public QEditPolar
void slotHelp();
void customMinRange_toggled(bool);
void customMaxRange_toggled(bool);
Ufkt *m_updatedfunction;
};
#endif
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