[Kst] branches/work/kst/portto4/kst/src/datasources/ascii

Peter Kümmel syntheticpp at gmx.net
Sat Feb 5 15:54:29 CET 2011


SVN commit 1218998 by kuemmel:

show a bit of the file content: this makes it superfluously to open a the data with a text editor

 M  +10 -0     asciiconfig.ui  
 M  +41 -17    asciiplugin.cpp  
 M  +21 -0     asciiplugin.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfig.ui #1218997:1218998
@@ -12,6 +12,16 @@
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
+    <widget class="QLabel" name="_labelBeginning">
+     <property name="text">
+      <string>First 100 lines </string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QPlainTextEdit" name="_showBeginning"/>
+   </item>
+   <item>
     <layout class="QGridLayout">
      <item row="0" column="0">
       <widget class="QLabel" name="textLabel1">
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1218997:1218998
@@ -22,6 +22,7 @@
 #include <QFile>
 #include <QFileInfo>
 #include <QButtonGroup>
+#include <QPlainTextEdit>
 
 
 //
@@ -42,6 +43,11 @@
   bgroup->addButton(_custom, AsciiSourceConfig::Custom);
   bgroup->addButton(_fixed, AsciiSourceConfig::Fixed);
   connect(bgroup, SIGNAL(buttonClicked(int)), this, SLOT(columnLayoutChanged(int)));
+
+  _showBeginning->setFont(  QFont("Courier"));
+  _showBeginning->setReadOnly(true);
+  _showBeginning->setLineWrapMode(QPlainTextEdit::NoWrap);
+
 }
 
 
@@ -54,7 +60,28 @@
   }
 }
 
+void ConfigWidgetAsciiInternal::showBeginning()
+{
+  QFile file(_filename);
+  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+    return;
+  }
 
+  int lines_read = 1;
+  QTextStream in(&file);
+  QStringList lines;
+  while (!in.atEnd() && lines_read <= 100) {
+    lines << QString("%1:").arg(lines_read, 3) + in.readLine();
+    lines_read++;
+  }
+
+  _showBeginning->setPlainText(lines.join("\n"));
+  _showBeginning->moveCursor(QTextCursor::Start);
+
+  _labelBeginning->setText(QString("First 100 lines in file '%1'").arg(QFileInfo(_filename).fileName()));
+}
+
+
 AsciiSourceConfig ConfigWidgetAsciiInternal::config()
 {
   AsciiSourceConfig config;
@@ -85,6 +112,13 @@
 }
 
 
+void ConfigWidgetAsciiInternal::setFilename(const QString& filename)
+{
+  _filename = filename;
+  showBeginning();
+}
+
+
 void ConfigWidgetAsciiInternal::setConfig(const AsciiSourceConfig& config)
 {
   _delimiters->setText(config._delimiters);
@@ -113,23 +147,6 @@
 }
 
 
-//
-// ConfigWidgetAscii
-//
-
-class ConfigWidgetAscii : public Kst::DataSourceConfigWidget
-{
-  public:
-    ConfigWidgetAscii(QSettings&);
-    ~ConfigWidgetAscii();
-
-    void load();
-    void save();
-
-    ConfigWidgetAsciiInternal *_ac;
-};
-
-
 ConfigWidgetAscii::ConfigWidgetAscii(QSettings& s) : Kst::DataSourceConfigWidget(s) {
   QGridLayout *layout = new QGridLayout(this);
   _ac = new ConfigWidgetAsciiInternal(this);
@@ -142,6 +159,12 @@
 }
 
 
+void ConfigWidgetAscii::setFilename(const QString& filename)
+{
+  _ac->setFilename(filename);
+}
+
+
 void ConfigWidgetAscii::load() {
   AsciiSourceConfig config;
   if (hasInstance())
@@ -404,6 +427,7 @@
   Q_UNUSED(filename)
   ConfigWidgetAscii *config = new ConfigWidgetAscii(*cfg);
   config->load();
+  config->setFilename(filename);
   return config;
 }
 
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.h #1218997:1218998
@@ -78,6 +78,7 @@
 };
 
 
+
 class ConfigWidgetAsciiInternal : public QWidget, public Ui_AsciiConfig
 {
   Q_OBJECT
@@ -87,14 +88,34 @@
 
     AsciiSourceConfig config();
     void setConfig(const AsciiSourceConfig&);
+    void setFilename(const QString& filename);
 
   private Q_SLOTS:
     void columnLayoutChanged(int);
+    void showBeginning();
 
   private:
     const int _index_offset;
+    QString _filename;
 
 };
 
+
+class ConfigWidgetAscii : public Kst::DataSourceConfigWidget
+{
+  public:
+    ConfigWidgetAscii(QSettings&);
+    ~ConfigWidgetAscii();
+
+    void load();
+    void save();
+
+    void setFilename(const QString& filename);
+
+    ConfigWidgetAsciiInternal *_ac;
+};
+
+
+
 #endif
 // vim: ts=2 sw=2 et


More information about the Kst mailing list