[Kst] branches/work/kst/portto4/kst/src
Peter Kümmel
syntheticpp at gmx.net
Thu Apr 26 21:37:53 UTC 2012
SVN commit 1292007 by kuemmel:
catch wrong parameters in ascii config dialog
M +10 -26 datasources/ascii/asciiconfig.ui
M +33 -3 datasources/ascii/asciiplugin.cpp
M +2 -1 datasources/ascii/asciiplugin.h
M +6 -0 libkst/datasource.cpp
M +5 -0 libkst/datasource.h
M +6 -5 libkstapp/datasourcedialog.cpp
M +1 -0 libkstapp/datasourcedialog.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfig.ui #1292006:1292007
@@ -476,52 +476,36 @@
</hints>
</connection>
<connection>
- <sender>_readFields</sender>
+ <sender>_custom</sender>
<signal>toggled(bool)</signal>
- <receiver>_readUnits</receiver>
+ <receiver>_columnDelimiter</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>62</x>
- <y>162</y>
+ <x>34</x>
+ <y>312</y>
</hint>
<hint type="destinationlabel">
- <x>65</x>
- <y>186</y>
+ <x>158</x>
+ <y>311</y>
</hint>
</hints>
</connection>
<connection>
<sender>_readFields</sender>
<signal>toggled(bool)</signal>
- <receiver>_unitsLine</receiver>
+ <receiver>_readUnits</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
- <x>100</x>
+ <x>62</x>
<y>162</y>
</hint>
<hint type="destinationlabel">
- <x>331</x>
- <y>192</y>
+ <x>65</x>
+ <y>186</y>
</hint>
</hints>
</connection>
- <connection>
- <sender>_custom</sender>
- <signal>toggled(bool)</signal>
- <receiver>_columnDelimiter</receiver>
- <slot>setEnabled(bool)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>34</x>
- <y>312</y>
- </hint>
- <hint type="destinationlabel">
- <x>158</x>
- <y>311</y>
- </hint>
- </hints>
- </connection>
</connections>
</ui>
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1292006:1292007
@@ -23,8 +23,8 @@
#include <QFileInfo>
#include <QButtonGroup>
#include <QPlainTextEdit>
+#include <QMessageBox>
-
//
// ConfigWidgetAsciiInternal
//
@@ -48,8 +48,17 @@
_showBeginning->setReadOnly(true);
_showBeginning->setLineWrapMode(QPlainTextEdit::NoWrap);
+ connect(_readFields, SIGNAL(toggled(bool)), this, SLOT(updateUnitLineEnabled(bool)));
}
+void ConfigWidgetAsciiInternal::updateUnitLineEnabled(bool checked)
+{
+ if (checked && _readUnits->isChecked()) {
+ _unitsLine->setEnabled(true);
+ } else {
+ _unitsLine->setEnabled(false);
+ }
+}
void ConfigWidgetAsciiInternal::columnLayoutChanged(int idx)
{
@@ -111,7 +120,6 @@
return config;
}
-
void ConfigWidgetAsciiInternal::setFilename(const QString& filename)
{
_filename = filename;
@@ -130,6 +138,7 @@
_readUnits->setChecked(config._readUnits);
_useDot->setChecked(config._useDot);
_useComma->setChecked(!config._useDot);
+ updateUnitLineEnabled(config._readFields);
_startLine->setValue(config._dataLine + _index_offset);
_fieldsLine->setValue(config._fieldsLine + _index_offset);
@@ -213,8 +222,29 @@
}
}
+bool ConfigWidgetAscii::isOkAcceptabe() const {
+ AsciiSourceConfig config = _ac->config();
+ QString msg;
+ if (config._readFields) {
+ if (config._fieldsLine == config._dataLine) {
+ msg = QString("Line %1 could not list field names AND values!").arg(config._fieldsLine + 1);
+ }
+ if (config._readUnits) {
+ if (config._unitsLine == config._dataLine) {
+ msg = QString("Line %1 could not list units AND values!").arg(config._unitsLine + 1);
+ }
+ if (config._unitsLine == config._fieldsLine) {
+ msg = QString("Line %1 could not list field names AND units!").arg(config._unitsLine + 1);
+ }
+ }
+ }
+ if (!msg.isEmpty()) {
+ QMessageBox::critical(0, "Inconsistent parameters", msg);
+ return false;
+ }
+ return true;
+}
-
//
// AsciiPlugin
//
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.h #1292006:1292007
@@ -93,11 +93,11 @@
private Q_SLOTS:
void columnLayoutChanged(int);
void showBeginning();
+ void updateUnitLineEnabled(bool);
private:
const int _index_offset;
QString _filename;
-
};
@@ -109,6 +109,7 @@
void load();
void save();
+ bool isOkAcceptabe() const;
void setFilename(const QString& filename);
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #1292006:1292007
@@ -123,7 +123,10 @@
//This is still ugly to me...
w->_instance = this;
+
+ // TODO check if not all plugins already have load() called
w->load();
+
return w;
}
@@ -420,6 +423,9 @@
return _cfg;
}
+bool DataSourceConfigWidget::isOkAcceptabe() const {
+ return true;
+}
bool DataSourceConfigWidget::hasInstance() const {
return _instance != 0L;
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #1292006:1292007
@@ -331,6 +331,11 @@
DataSourcePtr instance() const;
bool hasInstance() const;
+ // Check if the widget could be closed,
+ // and the user has not entered invalid parameters.
+ virtual bool isOkAcceptabe() const;
+
+
public slots:
virtual void load() = 0;
virtual void save() = 0;
--- branches/work/kst/portto4/kst/src/libkstapp/datasourcedialog.cpp #1292006:1292007
@@ -26,8 +26,8 @@
QVBoxLayout *layout = new QVBoxLayout(this);
_dataSource->readLock();
- QWidget *widget = _dataSource->configWidget();
- connect(this, SIGNAL(ok()), widget, SLOT(save()));
+ _configWidget = _dataSource->configWidget();
+ connect(this, SIGNAL(ok()), _configWidget, SLOT(save()));
if (mode == DataDialog::Edit) {
connect(this, SIGNAL(ok()), this, SLOT(disableReuse()));
@@ -35,8 +35,8 @@
_dataSource->unlock();
- widget->setParent(this);
- layout->addWidget(widget);
+ _configWidget->setParent(this);
+ layout->addWidget(_configWidget);
_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout->addWidget(_buttonBox);
@@ -59,13 +59,14 @@
_dataSource->disableReuse();
}
-
void DataSourceDialog::buttonClicked(QAbstractButton *button) {
QDialogButtonBox::StandardButton std = _buttonBox->standardButton(button);
switch(std) {
case QDialogButtonBox::Ok:
+ if (_configWidget->isOkAcceptabe()) {
emit ok();
accept();
+ }
break;
case QDialogButtonBox::Cancel:
emit cancel();
--- branches/work/kst/portto4/kst/src/libkstapp/datasourcedialog.h #1292006:1292007
@@ -46,6 +46,7 @@
private:
DataSourcePtr _dataSource;
QDialogButtonBox *_buttonBox;
+ DataSourceConfigWidget* _configWidget;
};
}
More information about the Kst
mailing list