[Kst] branches/work/kst/portto4/kst/src
Peter Kümmel
syntheticpp at gmx.net
Wed May 1 10:10:47 UTC 2013
SVN commit 1351910 by kuemmel:
add preview widget for ascii data
this changes the modality to window only, so other windows are not
blocked when the ascii dialog is open.
M +2 -2 datasources/ascii/asciiconfig.ui
M +29 -7 datasources/ascii/asciiconfigwidget.cpp
M +4 -0 datasources/ascii/asciiconfigwidget.h
M +2 -1 libkst/datasource.h
M +1 -1 libkstapp/datasourcedialog.cpp
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfig.ui #1351909:1351910
@@ -34,9 +34,9 @@
</spacer>
</item>
<item>
- <widget class="QPushButton" name="pushButton">
+ <widget class="QPushButton" name="_previewButton">
<property name="text">
- <string>Preview First 100 Lines in New Window</string>
+ <string>Preview First 1000 Lines in New Window</string>
</property>
</widget>
</item>
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfigwidget.cpp #1351909:1351910
@@ -43,14 +43,18 @@
_showBeginning->setLineWrapMode(QPlainTextEdit::NoWrap);
_showBeginning->setMinimumSize(640, 100);
+ _previewWidget.setFont(QFont("Courier"));
+ _previewWidget.setReadOnly(true);
+ _previewWidget.setLineWrapMode(QPlainTextEdit::NoWrap);
+ _previewWidget.setMinimumSize(640, 300);
+
QObject::connect(_ctime, SIGNAL(toggled(bool)), this, SLOT(interpretationChanged(bool)));
QObject::connect(_seconds, SIGNAL(toggled(bool)), this, SLOT(interpretationChanged(bool)));
QObject::connect(_indexFreq, SIGNAL(toggled(bool)), this, SLOT(interpretationChanged(bool)));
QObject::connect(_formattedString, SIGNAL(toggled(bool)), this, SLOT(interpretationChanged(bool)));
-
+ QObject::connect(_previewButton, SIGNAL(clicked()), this, SLOT(showPreviewWindow()));
}
-
QString AsciiConfigWidgetInternal::readLine(QTextStream& in, int maxLength)
{
const QString line = in.readLine();
@@ -63,6 +67,20 @@
void AsciiConfigWidgetInternal::showBeginning()
{
+ showBeginning(_showBeginning, 100);
+ _labelBeginning->setText(QString("First lines of file '%1'").arg(QFileInfo(_filename).fileName()));
+}
+
+
+void AsciiConfigWidgetInternal::showPreviewWindow()
+{
+ showBeginning(&_previewWidget, 1000);
+ _previewWidget.setWindowTitle(_filename);
+ _previewWidget.show();
+}
+
+void AsciiConfigWidgetInternal::showBeginning(QPlainTextEdit* widget, int numberOfLines)
+{
QFile file(_filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return;
@@ -71,15 +89,13 @@
int lines_read = 1;
QTextStream in(&file);
QStringList lines;
- while (!in.atEnd() && lines_read <= 100) {
+ while (!in.atEnd() && lines_read <= numberOfLines) {
lines << QString("%1: ").arg(lines_read, 3) + readLine(in, 1000);
lines_read++;
}
- _showBeginning->setPlainText(lines.join("\n"));
- _showBeginning->moveCursor(QTextCursor::Start);
-
- _labelBeginning->setText(QString("First lines of file '%1'").arg(QFileInfo(_filename).fileName()));
+ widget->setPlainText(lines.join("\n"));
+ widget->moveCursor(QTextCursor::Start);
}
void AsciiConfigWidgetInternal::interpretationChanged(bool enabled) {
@@ -226,6 +242,12 @@
}
+void AsciiConfigWidget::setDialogParent(QDialog* parent)
+{
+ parent->setWindowModality(Qt::WindowModal);
+ DataSourceConfigWidget::setDialogParent(parent);
+}
+
void AsciiConfigWidget::setFilename(const QString& filename)
{
_ac->setFilename(filename);
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfigwidget.h #1351909:1351910
@@ -33,6 +33,7 @@
private Q_SLOTS:
void showBeginning();
+ void showPreviewWindow();
protected Q_SLOTS:
void interpretationChanged(bool enabled);
@@ -40,7 +41,9 @@
private:
const int _index_offset;
QString _filename;
+ QPlainTextEdit _previewWidget;
QString readLine(QTextStream& in, int maxLength);
+ void showBeginning(QPlainTextEdit* widget, int numberOfLines);
};
@@ -53,6 +56,7 @@
void load();
void save();
bool isOkAcceptabe() const;
+ void setDialogParent(QDialog* parent);
void setFilename(const QString& filename);
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #1351909:1351910
@@ -29,7 +29,7 @@
#include "datamatrix.h"
#include <QRunnable>
-#include <QWidget>
+#include <QDialog>
#include <QMap>
class QSettings;
@@ -358,6 +358,7 @@
// and the user has not entered invalid parameters.
virtual bool isOkAcceptabe() const;
+ virtual void setDialogParent(QDialog* parent) { setParent(parent); }
public slots:
virtual void load() = 0;
--- branches/work/kst/portto4/kst/src/libkstapp/datasourcedialog.cpp #1351909:1351910
@@ -35,7 +35,7 @@
_dataSource->unlock();
- _configWidget->setParent(this);
+ _configWidget->setDialogParent(this);
layout->addWidget(_configWidget);
_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
More information about the Kst
mailing list