[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Wed Sep 26 22:54:40 CEST 2007
SVN commit 717409 by treat:
We can now load vectors from disk through the ascii
datasource.
* Add new Kst::DataTab and Kst::DataSourceDialog classes
* Provide mechanism to call between datatab and datadialog
* Big changes to VectorDialog to create DataVectors
There is still something wrong with the data vectors.
Investigating...
M +16 -8 datadialog.cpp
M +10 -3 datadialog.h
A datasourcedialog.cpp [License: GPL (v2+)]
A datasourcedialog.h [License: GPL (v2+)]
A datatab.cpp [License: GPL (v2+)]
A datatab.h [License: GPL (v2+)]
M +8 -2 dialogpage.cpp
M +6 -1 dialogpage.h
M +16 -0 dialogtab.cpp
M +6 -0 dialogtab.h
M +6 -2 libkstapp.pro
M +125 -41 vectordialog.cpp
M +24 -8 vectordialog.h
--- branches/work/kst/portto4/kst/src/libkstapp/datadialog.cpp #717408:717409
@@ -11,7 +11,7 @@
#include "datadialog.h"
-#include "dialogtab.h"
+#include "datatab.h"
#include "dialogpage.h"
#include "editmultiplewidget.h"
@@ -27,13 +27,13 @@
namespace Kst {
DataDialog::DataDialog(QWidget *parent)
- : Dialog(parent), _dataObject(0) {
+ : Dialog(parent), _defaultTag("<Auto Name>"), _dataObject(0), _mode(New) {
createGui();
}
DataDialog::DataDialog(KstObjectPtr dataObject, QWidget *parent)
- : Dialog(parent), _dataObject(dataObject) {
+ : Dialog(parent), _dataObject(dataObject), _mode(Edit) {
createGui();
}
@@ -70,10 +70,12 @@
QPushButton *button = new QPushButton(tr("Edit Multiple >>"));
connect(button, SIGNAL(clicked()), this, SLOT(slotEditMultiple()));
- if (_dataObject)
- _tagName->setText(_dataObject->tagName());
- else
+ if (_dataObject) {
+ setTagName(_dataObject->tagName());
+ } else {
+ setTagName(tagName());
button->setVisible(false);
+ }
layout->addWidget(label);
layout->addWidget(_tagName);
@@ -84,11 +86,17 @@
QString DataDialog::tagName() const {
- return _tagName->text();
+ const QString tag = _tagName->text();
+ return tag.isEmpty() ? _defaultTag : tag;
}
-void DataDialog::addDataTab(DialogTab *tab) {
+void DataDialog::setTagName(const QString &tagName) {
+ _tagName->setText(tagName);
+}
+
+
+void DataDialog::addDataTab(DataTab *tab) {
DialogPage *page = new DialogPage(this);
page->setPageTitle(tab->tabTitle());
page->addDialogTab(tab);
--- branches/work/kst/portto4/kst/src/libkstapp/datadialog.h #717408:717409
@@ -22,20 +22,25 @@
namespace Kst {
-class DialogTab;
+class DataTab;
class KST_EXPORT DataDialog : public Dialog {
Q_OBJECT
public:
+ enum EditMode { New, Edit };
DataDialog(QWidget *parent = 0);
DataDialog(KstObjectPtr dataObject, QWidget *parent = 0);
virtual ~DataDialog();
- void addDataTab(DialogTab *tab);
+ EditMode editMode() const { return _mode; }
+ void addDataTab(DataTab *tab);
protected:
- QString tagName() const;
+ virtual QString tagName() const;
+ void setTagName(const QString &tagName);
+ QString defaultTag() const { return _defaultTag; }
+
KstObjectPtr dataObject() const { return _dataObject; }
void setDataObject(KstObjectPtr dataObject) { _dataObject = dataObject; }
@@ -50,8 +55,10 @@
void createGui();
private:
+ QString _defaultTag;
QLineEdit *_tagName;
KstObjectPtr _dataObject;
+ EditMode _mode;
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/dialogpage.cpp #717408:717409
@@ -11,14 +11,15 @@
#include "dialogpage.h"
+#include "dialog.h"
#include "dialogtab.h"
#include <QTabBar>
namespace Kst {
-DialogPage::DialogPage(QWidget *parent)
- : QTabWidget(parent) {
+DialogPage::DialogPage(Dialog *parent)
+ : QTabWidget(parent), _dialog(parent) {
tabBar()->setVisible(false);
}
@@ -28,6 +29,11 @@
}
+Dialog *DialogPage::dialog() const {
+ return _dialog;
+}
+
+
void DialogPage::addDialogTab(DialogTab *tab) {
connect(this, SIGNAL(ok()), tab, SIGNAL(ok()));
connect(this, SIGNAL(apply()), tab, SIGNAL(apply()));
--- branches/work/kst/portto4/kst/src/libkstapp/dialogpage.h #717408:717409
@@ -13,20 +13,24 @@
#define DIALOGPAGE_H
#include <QTabWidget>
+#include <QPointer>
#include "kst_export.h"
namespace Kst {
+class Dialog;
class DialogTab;
class KST_EXPORT DialogPage : public QTabWidget
{
Q_OBJECT
public:
- DialogPage(QWidget *parent);
+ DialogPage(Dialog *parent);
virtual ~DialogPage();
+ Dialog *dialog() const;
+
QString pageTitle() const { return _pageTitle; }
void setPageTitle(const QString &pageTitle) { _pageTitle = pageTitle; }
@@ -47,6 +51,7 @@
private:
QString _pageTitle;
QPixmap _pageIcon;
+ QPointer<Dialog> _dialog;
};
}
--- branches/work/kst/portto4/kst/src/libkstapp/dialogtab.cpp #717408:717409
@@ -11,6 +11,9 @@
#include "dialogtab.h"
+#include "dialog.h"
+#include "dialogpage.h"
+
namespace Kst {
DialogTab::DialogTab(QWidget *parent)
@@ -21,6 +24,19 @@
DialogTab::~DialogTab() {
}
+
+Dialog *DialogTab::dialog() const {
+ if (dialogPage())
+ return dialogPage()->dialog();
+ else
+ return 0;
}
+
+DialogPage *DialogTab::dialogPage() const {
+ return qobject_cast<DialogPage*>(parentWidget()->parentWidget());
+}
+
+}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/dialogtab.h #717408:717409
@@ -18,6 +18,9 @@
namespace Kst {
+class Dialog;
+class DialogPage;
+
//FIXME maybe we should really have a model...
class KST_EXPORT DialogTab : public QWidget
@@ -27,6 +30,9 @@
DialogTab(QWidget *parent);
virtual ~DialogTab();
+ Dialog *dialog() const;
+ DialogPage *dialogPage() const;
+
QString tabTitle() const { return _tabTitle; }
void setTabTitle(const QString &tabTitle) { _tabTitle = tabTitle; }
--- branches/work/kst/portto4/kst/src/libkstapp/libkstapp.pro #717408:717409
@@ -25,10 +25,12 @@
axis.cpp \
boxitem.cpp \
builtingraphics.cpp \
+ databutton.cpp \
+ databuttonaction.cpp \
datadialog.cpp \
datamanager.cpp \
- databutton.cpp \
- databuttonaction.cpp \
+ datasourcedialog.cpp \
+ datatab.cpp \
debugdialog.cpp \
debugnotifier.cpp \
dialog.cpp \
@@ -82,6 +84,8 @@
datadialog.h \
datamanager.h \
dataref.h \
+ datasourcedialog.h \
+ datatab.h \
debugdialog.h \
debugnotifier.h \
dialog.h \
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.cpp #717408:717409
@@ -12,19 +12,23 @@
#include "vectordialog.h"
#include "dialogpage.h"
+#include "datasourcedialog.h"
+#include "kstrvector.h"
#include "kstsvector.h"
#include "kstdatacollection.h"
#include "kstdataobjectcollection.h"
+#include "kstvectordefaults.h"
+#include "defaultprimitivenames.h"
+
#include <QDir>
-#include <QUrl>
namespace Kst {
VectorTab::VectorTab(QWidget *parent)
- : DialogTab(parent), _mode(ReadOnlyVector) {
+ : DataTab(parent), _mode(DataVector) {
setupUi(this);
setTabTitle(tr("Vector"));
@@ -37,6 +41,7 @@
this, SLOT(showConfigWidget()));
_fileName->setFile(QDir::currentPath());
+ //_fileName->setFile(KST::vectorDefaults.dataSource());
//FIXME need a solution for replacing kio for this...
_connect->setVisible(false);
@@ -47,6 +52,47 @@
}
+KstDataSourcePtr VectorTab::dataSource() const {
+ return _dataSource;
+}
+
+
+void VectorTab::setDataSource(KstDataSourcePtr dataSource) {
+ _dataSource = dataSource;
+}
+
+
+QString VectorTab::file() const {
+ return _fileName->file();
+}
+
+
+void VectorTab::setFile(const QString &file) {
+ _fileName->setFile(file);
+}
+
+
+QString VectorTab::field() const {
+ return _field->currentText();
+}
+
+
+void VectorTab::setField(const QString &field) {
+ _field->setCurrentIndex(_field->findText(field));
+}
+
+
+void VectorTab::setFieldList(const QStringList &fieldList) {
+ _field->clear();
+ _field->addItems(fieldList);
+}
+
+
+DataRange *VectorTab::dataRange() const {
+ return _dataRange;
+}
+
+
qreal VectorTab::from() const {
return _from->text().toDouble();
}
@@ -75,9 +121,9 @@
void VectorTab::readFromSourceChanged() {
if (_readFromSource->isChecked())
- setMode(ReadOnlyVector);
+ setVectorMode(DataVector);
else
- setMode(SlaveVector);
+ setVectorMode(GeneratedVector);
_rvectorGroup->setEnabled(_readFromSource->isChecked());
_dataRange->setEnabled(_readFromSource->isChecked());
@@ -93,11 +139,11 @@
_field->clear();
KST::dataSourceList.lock().readLock();
- _dataSource = KST::dataSourceList.findReusableFileName(QUrl(file));
+ _dataSource = KST::dataSourceList.findReusableFileName(file);
KST::dataSourceList.lock().unlock();
if (!_dataSource) {
- _dataSource = KstDataSource::loadSource(QUrl(file), QString());
+ _dataSource = KstDataSource::loadSource(file, QString());
}
if (!_dataSource) {
@@ -122,28 +168,7 @@
void VectorTab::showConfigWidget() {
- QDialog dialog(this);
-
- QVBoxLayout layout(&dialog);
-
- _dataSource->readLock();
- QWidget *widget = _dataSource->configWidget();
- widget->setParent(&dialog);
- layout.addWidget(widget);
- _dataSource->unlock();
-
- QDialogButtonBox box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
- layout.addWidget(&box);
-
-// if (isNew) {
-// connect(dlg, SIGNAL(okClicked()), _configWidget, SLOT(save()));
-// connect(dlg, SIGNAL(applyClicked()), _configWidget, SLOT(save()));
-// } else {
-// connect(dlg, SIGNAL(okClicked()), this, SLOT(markSourceAndSave()));
-// connect(dlg, SIGNAL(applyClicked()), this, SLOT(markSourceAndSave()));
-// }
-
- dialog.setLayout(&layout);
+ DataSourceDialog dialog(dataDialog()->editMode(), _dataSource, this);
dialog.exec();
}
@@ -174,31 +199,90 @@
}
-void VectorDialog::setDefaults() {
- //FIXME
+QString VectorDialog::tagName() const {
+ switch(_vectorTab->vectorMode()) {
+ case VectorTab::DataVector:
+ {
+ QString tagName = DataDialog::tagName();
+ tagName.replace(defaultTag(), _vectorTab->field());
+ return KST::suggestVectorName(tagName);
+ }
+ case VectorTab::GeneratedVector:
+ {
+ if (DataDialog::tagName() == defaultTag()) {
+ const qreal from = _vectorTab->from();
+ const qreal to = _vectorTab->to();
+ return KST::suggestVectorName(QString("(%1..%2)").arg(from).arg(to));
+ }
+ }
+ default:
+ return DataDialog::tagName();
+ }
}
KstObjectPtr VectorDialog::createNewDataObject() const {
+ switch(_vectorTab->vectorMode()) {
+ case VectorTab::DataVector:
+ return createNewDataVector();
+ case VectorTab::GeneratedVector:
+ return createNewGeneratedVector();
+ default:
+ return 0;
+ }
+}
- if (_vectorTab->mode() == VectorTab::ReadOnlyVector) {
- qDebug() << "ReadOnlyVectors not supported yet...!" << endl;
+KstObjectPtr VectorDialog::createNewDataVector() const {
+ const KstDataSourcePtr dataSource = _vectorTab->dataSource();
+
+ //FIXME better validation than this please...
+ if (!dataSource)
return 0;
- } else if (_vectorTab->mode() == VectorTab::SlaveVector) {
+ const QString field = _vectorTab->field();
+ const DataRange *dataRange = _vectorTab->dataRange();
+ const KstObjectTag tag = KstObjectTag(tagName(), dataSource->tag(), false);
- const qreal from = _vectorTab->from();
- const qreal to = _vectorTab->to();
- const int numberOfSamples = _vectorTab->numberOfSamples();
- const KstObjectTag tag = KstObjectTag(tagName(), KstObjectTag::globalTagContext);
+ qDebug() << "Creating new data vector ===>"
+ << "\n\tfileName:" << dataSource->fileName()
+ << "\n\tfileType:" << dataSource->fileType()
+ << "\n\tfield:" << field
+ << "\n\ttag:" << tag.tag()
+ << "\n\tstart:" << (dataRange->countFromEnd() ? -1 : int(dataRange->start()))
+ << "\n\trange:" << (dataRange->readToEnd() ? -1 : int(dataRange->range()))
+ << "\n\tskip:" << dataRange->skip()
+ << "\n\tdoSkip:" << (dataRange->doSkip() ? "true" : "false")
+ << "\n\tdoFilter:" << (dataRange->doFilter() ? "true" : "false")
+ << endl;
- KstSVectorPtr vector = new KstSVector(from, to, numberOfSamples, tag);
- return static_cast<KstObjectPtr>(vector);
+ KstRVectorPtr vector = new KstRVector(
+ dataSource, field, tag,
+ dataRange->countFromEnd() ? -1 : int(dataRange->start()),
+ dataRange->readToEnd() ? -1 : int(dataRange->range()),
+ dataRange->skip(),
+ dataRange->doSkip(),
+ dataRange->doFilter());
- }
+ return static_cast<KstObjectPtr>(vector);
+}
- return 0;
+
+KstObjectPtr VectorDialog::createNewGeneratedVector() const {
+ const qreal from = _vectorTab->from();
+ const qreal to = _vectorTab->to();
+ const int numberOfSamples = _vectorTab->numberOfSamples();
+ const KstObjectTag tag = KstObjectTag(tagName(), KstObjectTag::globalTagContext);
+
+ qDebug() << "Creating new generated vector ===>"
+ << "\n\tfrom:" << from
+ << "\n\tto:" << to
+ << "\n\tnumberOfSamples:" << numberOfSamples
+ << "\n\ttag:" << tag.tag()
+ << endl;
+
+ KstSVectorPtr vector = new KstSVector(from, to, numberOfSamples, tag);
+ return static_cast<KstObjectPtr>(vector);
}
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.h #717408:717409
@@ -13,7 +13,7 @@
#define VECTORDIALOG_H
#include "datadialog.h"
-#include "dialogtab.h"
+#include "datatab.h"
#include "ui_vectortab.h"
@@ -25,18 +25,32 @@
namespace Kst {
-class KST_EXPORT VectorTab : public DialogTab, Ui::VectorTab {
+class KST_EXPORT VectorTab : public DataTab, Ui::VectorTab {
Q_OBJECT
public:
- enum Mode { ReadOnlyVector, SlaveVector };
+ enum VectorMode { DataVector, GeneratedVector };
VectorTab(QWidget *parent = 0);
virtual ~VectorTab();
- Mode mode() const { return _mode; }
- void setMode(Mode mode) { _mode = mode; }
+ VectorMode vectorMode() const { return _mode; }
+ void setVectorMode(VectorMode mode) { _mode = mode; }
- //Slave vector mode methods...
+ //DataVector mode methods...
+ KstDataSourcePtr dataSource() const;
+ void setDataSource(KstDataSourcePtr dataSource);
+
+ QString file() const;
+ void setFile(const QString &file);
+
+ QString field() const;
+ void setField(const QString &field);
+
+ void setFieldList(const QStringList &fieldList);
+
+ DataRange *dataRange() const;
+
+ //GeneratedVector methods...
qreal from() const;
void setFrom(qreal from);
@@ -52,7 +66,7 @@
void showConfigWidget();
private:
- Mode _mode;
+ VectorMode _mode;
KstDataSourcePtr _dataSource;
};
@@ -64,11 +78,13 @@
virtual ~VectorDialog();
protected:
+ virtual QString tagName() const;
virtual KstObjectPtr createNewDataObject() const;
virtual KstObjectPtr editExistingDataObject() const;
private:
- void setDefaults();
+ KstObjectPtr createNewDataVector() const;
+ KstObjectPtr createNewGeneratedVector() const;
private:
VectorTab *_vectorTab;
More information about the Kst
mailing list