Commit a1ba91bd authored by David Saxton's avatar David Saxton

Improved function parameter editor (added Cancel button, made editing inline),

and fixed bug in importing/exporting parameters (was passing the wrong url to
QFile).

svn path=/trunk/KDE/kdeedu/kmplot/; revision=524389
parent e4c068fa
......@@ -688,7 +688,6 @@ void View::paintEvent(QPaintEvent *)
p.setPen( highlightColor );
p.setBrush( backgroundColor );
/// \todo make this draw blue-black dotline (atm, just draws transparent-black dotline for some strange reason)
p.setBackgroundMode (Qt::OpaqueMode);
p.setBackground (Qt::blue);
......
......@@ -86,6 +86,7 @@ void KConstantEditor::cmdNew_clicked()
{
QTreeWidgetItem * item = new QTreeWidgetItem( constantList );
constantList->setCurrentItem( item );
nameEdit->setFocus();
}
......@@ -135,7 +136,6 @@ void KConstantEditor::selectedConstantChanged( QTreeWidgetItem * current )
nameEdit->setText( name );
valueEdit->setText( value );
}
......
......@@ -42,10 +42,12 @@
#include "kparametereditor.h"
#include <assert.h>
class ParameterValueList;
KParameterEditor::KParameterEditor(XParser *m, QList<ParameterValueItem> *l, QWidget *parent )
: KDialog( parent, i18n("Parameter Editor"), Ok ),
: KDialog( parent, i18n("Parameter Editor"), Ok|Cancel ),
m_parameter(l),
m_parser(m)
{
......@@ -57,19 +59,24 @@ KParameterEditor::KParameterEditor(XParser *m, QList<ParameterValueItem> *l, QWi
m_mainWidget->list->sortItems();
connect( m_mainWidget->cmdNew, SIGNAL( clicked() ), this, SLOT( cmdNew_clicked() ));
connect( m_mainWidget->cmdEdit, SIGNAL( clicked() ), this, SLOT( cmdEdit_clicked() ));
connect( m_mainWidget->cmdDelete, SIGNAL( clicked() ), this, SLOT( cmdDelete_clicked() ));
connect( m_mainWidget->cmdImport, SIGNAL( clicked() ), this, SLOT( cmdImport_clicked() ));
connect( m_mainWidget->cmdExport, SIGNAL( clicked() ), this, SLOT( cmdExport_clicked() ));
connect( m_mainWidget->list, SIGNAL( itemDoubleClicked( QListWidgetItem * ) ), this, SLOT( varlist_doubleClicked( QListWidgetItem *) ));
connect( m_mainWidget->list, SIGNAL( itemClicked ( QListWidgetItem * ) ), this, SLOT( varlist_clicked(QListWidgetItem * ) ));
connect( m_mainWidget->list, SIGNAL(currentItemChanged( QListWidgetItem *, QListWidgetItem * )), this, SLOT(selectedConstantChanged( QListWidgetItem * )) );
connect( m_mainWidget->value, SIGNAL( textEdited( const QString & ) ), this, SLOT( saveCurrentValue() ) );
connect( m_mainWidget->value, SIGNAL( textChanged( const QString & ) ), this, SLOT( checkValueValid() ) );
checkValueValid();
m_mainWidget->value->setFocus();
}
KParameterEditor::~KParameterEditor()
{
}
void KParameterEditor::accept()
{
kDebug() << "saving\n";
......@@ -85,71 +92,58 @@ void KParameterEditor::accept()
KDialog::accept();
}
void KParameterEditor::cmdNew_clicked()
{
QString result="";
while (1)
{
bool ok;
result = KInputDialog::getText( i18n("Parameter Value"), i18n( "Enter a new parameter value:" ), result, &ok );
if ( !ok)
return;
m_parser->eval( result );
if ( m_parser->parserError(false) != 0 )
{
m_parser->parserError( true );
continue;
}
if ( checkTwoOfIt(result) )
{
KMessageBox::sorry(0,i18n("The value %1 already exists and will therefore not be added.").arg(result));
continue;
}
m_mainWidget->list->addItem(result);
m_mainWidget->list->sortItems();
break;
}
QListWidgetItem * item = new QListWidgetItem( m_mainWidget->list );
m_mainWidget->list->setCurrentItem( item );
m_mainWidget->value->setFocus();
}
void KParameterEditor::cmdEdit_clicked()
void KParameterEditor::selectedConstantChanged( QListWidgetItem * current )
{
QListWidgetItem * currentItem = m_mainWidget->list->currentItem();
QString result = currentItem ? currentItem->text() : QString::null;
while (1)
{
bool ok;
result = KInputDialog::getText( i18n("Parameter Value"), i18n( "Enter a new parameter value:" ), result, &ok );
if ( !ok)
return;
m_parser->eval(result);
if ( m_parser->parserError(false) != 0)
{
m_parser->parserError( true );
continue;
}
if ( checkTwoOfIt(result) )
{
currentItem = m_mainWidget->list->currentItem();
QString currentText = currentItem ? currentItem->text() : QString::null;
if( result != currentText )
KMessageBox::sorry(0,i18n("The value %1 already exists.").arg(result));
continue;
}
m_mainWidget->list->takeItem( m_mainWidget->list->currentRow() );
m_mainWidget->list->addItem(result);
m_mainWidget->list->sortItems();
break;
}
m_mainWidget->cmdDelete->setEnabled( current != 0 );
m_mainWidget->value->setText( current ? current->text() : QString::null );
}
void KParameterEditor::cmdDelete_clicked()
{
delete m_mainWidget->list->takeItem( m_mainWidget->list->currentRow() );
QListWidgetItem * item = m_mainWidget->list->currentItem();
if ( !item )
return;
m_mainWidget->value->clear();
m_mainWidget->list->takeItem( m_mainWidget->list->currentRow() );
delete item;
m_mainWidget->cmdDelete->setEnabled( m_mainWidget->list->currentItem() != 0 );
m_mainWidget->list->sortItems();
}
void KParameterEditor::saveCurrentValue()
{
QListWidgetItem * current = m_mainWidget->list->currentItem();
if ( !current )
current = new QListWidgetItem( m_mainWidget->list );
current->setText( m_mainWidget->value->text() );
m_mainWidget->list->setCurrentItem( current );
}
bool KParameterEditor::checkValueValid()
{
QString valueText = m_mainWidget->value->text();
(double) m_parser->eval( valueText );
bool valid = (m_parser->parserError( false ) == 0);
m_mainWidget->valueInvalidLabel->setVisible( !valueText.isEmpty() && !valid );
return valid;
}
void KParameterEditor::cmdImport_clicked()
{
KUrl url = KFileDialog::getOpenURL( QString(),i18n("*.txt|Plain Text File "));
......@@ -175,7 +169,7 @@ void KParameterEditor::cmdImport_clicked()
file.setFileName(tmpfile);
}
else
file.setFileName(url.prettyURL(0) );
file.setFileName(url.path() );
if ( file.open(QIODevice::ReadOnly) )
{
......@@ -216,6 +210,7 @@ void KParameterEditor::cmdImport_clicked()
KIO::NetAccess::removeTempFile( tmpfile );
}
void KParameterEditor::cmdExport_clicked()
{
if ( !m_mainWidget->list->count() )
......@@ -258,7 +253,8 @@ void KParameterEditor::cmdExport_clicked()
}
else
{
file.setFileName(url.prettyURL(0));
kDebug() << "url.path()="<<url.path()<<endl;
file.setFileName(url.path());
if (file.open( QIODevice::WriteOnly ) )
{
QTextStream stream(&file);
......@@ -279,25 +275,6 @@ void KParameterEditor::cmdExport_clicked()
}
void KParameterEditor::varlist_clicked( QListWidgetItem * item )
{
if (item)
{
m_mainWidget->cmdEdit->setEnabled(true);
m_mainWidget->cmdDelete->setEnabled(true);
}
else
{
m_mainWidget->cmdEdit->setEnabled(false);
m_mainWidget->cmdDelete->setEnabled(false);
}
}
void KParameterEditor::varlist_doubleClicked( QListWidgetItem * )
{
cmdEdit_clicked();
}
bool KParameterEditor::checkTwoOfIt(const QString & text)
{
......
......@@ -47,12 +47,18 @@ public:
public slots:
void cmdNew_clicked();
void cmdEdit_clicked();
void cmdDelete_clicked();
void cmdImport_clicked();
void cmdExport_clicked();
void varlist_clicked( QListWidgetItem * );
void varlist_doubleClicked( QListWidgetItem * );
///actions for the visible constant list
void selectedConstantChanged( QListWidgetItem * current );
/// updates whether or not the "value is invalid" label is shown, (and returns the validity of the current value)
bool checkValueValid();
/// saves the value being edited
void saveCurrentValue();
virtual void accept();
......
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>455</width>
<height>245</height>
<width>381</width>
<height>482</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -22,51 +22,45 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="6" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
<item row="0" column="1" >
<widget class="QLabel" name="valueInvalidLabel" >
<property name="toolTip" >
<string>The value must be a number (e.g. "pi^2")</string>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
<property name="text" >
<string>(invalid)</string>
</property>
</spacer>
</widget>
</item>
<item rowspan="7" row="0" column="0" >
<item rowspan="6" row="1" column="0" >
<widget class="QListWidget" name="list" />
</item>
<item row="5" column="1" >
<widget class="KPushButton" name="cmdExport" >
<property name="enabled" >
<bool>true</bool>
</property>
<item row="1" column="1" >
<widget class="KPushButton" name="cmdNew" >
<property name="toolTip" >
<string>Export values to a textfile</string>
<string>Add a new constant</string>
</property>
<property name="whatsThis" >
<string>Export values to a textfile. Every value in the parameter list will be written to one line in the file.</string>
<string>Click this button to add a new constant.</string>
</property>
<property name="text" >
<string>&amp;Export...</string>
<string>&amp;New</string>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="KPushButton" name="cmdImport" >
<item row="2" column="1" >
<widget class="KPushButton" name="cmdDelete" >
<property name="enabled" >
<bool>true</bool>
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Import values from a textfile</string>
<string>delete selected constant</string>
</property>
<property name="whatsThis" >
<string>Import values from a textfile. Every line in the file is parsed as a value or expression.</string>
<string>Click here to delete the selected constant; it can only be removed if it is not currently used by a plot.</string>
</property>
<property name="text" >
<string>&amp;Import...</string>
<string>&amp;Delete</string>
</property>
</widget>
</item>
......@@ -80,61 +74,71 @@
</property>
<property name="sizeHint" >
<size>
<width>129</width>
<height>16</height>
<width>51</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" >
<widget class="KPushButton" name="cmdDelete" >
<item row="4" column="1" >
<widget class="KPushButton" name="cmdImport" >
<property name="enabled" >
<bool>false</bool>
<bool>true</bool>
</property>
<property name="toolTip" >
<string>delete selected constant</string>
<string>Import values from a textfile</string>
</property>
<property name="whatsThis" >
<string>Click here to delete the selected constant; it can only be removed if it is not currently used by a plot.</string>
<string>Import values from a textfile. Every line in the file is parsed as a value or expression.</string>
</property>
<property name="text" >
<string>&amp;Delete</string>
<string>&amp;Import...</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="KPushButton" name="cmdNew" >
<item row="5" column="1" >
<widget class="KPushButton" name="cmdExport" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="toolTip" >
<string>Add a new constant</string>
<string>Export values to a textfile</string>
</property>
<property name="whatsThis" >
<string>Click this button to add a new constant.</string>
<string>Export values to a textfile. Every value in the parameter list will be written to one line in the file.</string>
</property>
<property name="text" >
<string>&amp;New...</string>
<string>&amp;Export...</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="KPushButton" name="cmdEdit" >
<property name="enabled" >
<bool>false</bool>
</property>
<property name="toolTip" >
<string>Change the value of a user-defined constant</string>
</property>
<property name="whatsThis" >
<string>Click here to edit the value of the selected constant. Its name cannot be changed.</string>
<item row="6" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="text" >
<string>&amp;Change Value...</string>
<property name="sizeHint" >
<size>
<width>71</width>
<height>281</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="0" column="0" >
<widget class="KLineEdit" name="value" />
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends></extends>
<header>klineedit.h</header>
<container>0</container>
<pixmap></pixmap>
</customwidget>
<customwidget>
<class>KPushButton</class>
<extends></extends>
......
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