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

Peter Kümmel syntheticpp at gmx.net
Tue Oct 16 14:48:01 UTC 2012


SVN commit 1320708 by kuemmel:

add option to limit file buffer size

 M  +36 -5     asciiconfig.ui  
 M  +7 -9      asciifilebuffer.cpp  
 M  +2 -3      asciifilebuffer.h  
 M  +24 -0     asciiplugin.cpp  
 M  +1 -0      asciiplugin.h  
 M  +6 -1      asciisource.cpp  
 M  +17 -1     asciisourceconfig.cpp  
 M  +6 -0      asciisourceconfig.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfig.ui #1320707:1320708
@@ -18,17 +18,17 @@
      </property>
     </widget>
    </item>
-   <item row="1" column="0">
+   <item row="1" column="0" rowspan="2">
     <widget class="QPlainTextEdit" name="_showBeginning"/>
    </item>
-   <item row="1" column="1">
+   <item row="1" column="1" rowspan="2" colspan="2">
     <widget class="Line" name="verticalLine">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
     </widget>
    </item>
-   <item row="1" column="2">
+   <item row="2" column="2">
     <layout class="QVBoxLayout" name="verticalLayout">
      <item>
       <widget class="QGroupBox" name="headerButtonGroup">
@@ -406,16 +406,47 @@
        </layout>
       </widget>
      </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item>
+        <widget class="QCheckBox" name="_limitFileBuffer">
+         <property name="text">
+          <string>Limit file buffer sizt to (MB):</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="_limitFileBufferSize">
+         <property name="text">
+          <string>128</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer_2">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
     </layout>
    </item>
-   <item row="2" column="0" colspan="3">
+    </layout>
+   </item>
+   <item row="3" column="0" colspan="3">
     <widget class="Line" name="line">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </widget>
    </item>
-   <item row="3" column="0">
+   <item row="4" column="0">
     <widget class="QCheckBox" name="_applyDefault">
      <property name="text">
       <string>Apply these settings as default</string>
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.cpp #1320707:1320708
@@ -118,20 +118,14 @@
   return chunks;
 }
 
+
 //-------------------------------------------------------------------------------------------
-void AsciiFileBuffer::read(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes)
+void AsciiFileBuffer::readWholeFile(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes)
 {
   clear();
-  if (!_file) {
+  if (!_file)
     return;
-  }
-  //readWholeFile(rowIndex, start, bytesToRead, maximalBytes);
-  readFileSlidingWindow(rowIndex, start, bytesToRead, maximalBytes);
-}
 
-//-------------------------------------------------------------------------------------------
-void AsciiFileBuffer::readWholeFile(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes)
-{
   // first try to read the whole file into one array
   AsciiFileData wholeFile;
   wholeFile.read(*_file, start, bytesToRead, maximalBytes);
@@ -172,6 +166,10 @@
 //-------------------------------------------------------------------------------------------
 void AsciiFileBuffer::readFileSlidingWindow(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes)
 {
+  clear();
+  if (!_file)
+    return;
+
   int chunkSize = qMin((size_t) 10 * MB, maxAllocate);
   chunkSize = 2 * MB;
   _fileData = splitFile(chunkSize, rowIndex, start, bytesToRead);
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.h #1320707:1320708
@@ -32,7 +32,8 @@
   void clear();
 
   void setFile(QFile* file);
-  void read(const RowIndex& rowIndex, int start, int numberOfBytes, int maximalBytes = -1);
+  void readWholeFile(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes = -1);
+  void readFileSlidingWindow(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes = -1);
 
   const QVector<AsciiFileData>& data() const;
 
@@ -46,8 +47,6 @@
 
   void logData(const QVector<AsciiFileData>& chunks) const;
   const QVector<AsciiFileData> splitFile(int chunkSize, const RowIndex& rowIndex, int start, int bytesToRead) const;
-  void readWholeFile(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes);
-  void readFileSlidingWindow(const RowIndex& rowIndex, int start, int bytesToRead, int maximalBytes);
 };
 
 #endif
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1320707:1320708
@@ -44,6 +44,7 @@
   _showBeginning->setLineWrapMode(QPlainTextEdit::NoWrap);
 
   connect(_readFields, SIGNAL(toggled(bool)), this, SLOT(updateUnitLineEnabled(bool)));
+  connect(_limitFileBuffer, SIGNAL(toggled(bool)), this, SLOT(updateFrameBuffer(bool)));
 }
 
 void ConfigWidgetAsciiInternal::updateUnitLineEnabled(bool checked)
@@ -55,6 +56,16 @@
   }
 }
 
+void ConfigWidgetAsciiInternal::updateFrameBuffer(bool checked)
+{
+  if (checked) {
+    _limitFileBufferSize->setEnabled(true);
+  } else {
+    _limitFileBufferSize->setEnabled(false);
+  }
+}
+
+
 void ConfigWidgetAsciiInternal::columnLayoutChanged(int idx)
 {
   if (idx == AsciiSourceConfig::Fixed) {
@@ -64,6 +75,7 @@
   }
 }
 
+
 void ConfigWidgetAsciiInternal::showBeginning()
 {
   QFile file(_filename);
@@ -112,6 +124,13 @@
   config._fieldsLine = _fieldsLine->value() - _index_offset;
   config._unitsLine = _unitsLine->value() - _index_offset;
 
+  config._limitFileBuffer = _limitFileBuffer->isChecked();
+  bool ok;
+  int size = _limitFileBufferSize->text().toInt(&ok);
+  if (ok) {
+    config._limitFileBufferSize = size * 1024 * 1024;
+  }
+
   return config;
 }
 
@@ -148,6 +167,11 @@
     _whitespace->setChecked(true);
   }
   columnLayoutChanged(ct);
+
+  _limitFileBuffer->setChecked(config._limitFileBuffer);
+  _limitFileBufferSize->setText(QString::number(config._limitFileBufferSize / 1024 / 1024));
+  updateFrameBuffer(config._limitFileBuffer);
+
 }
 
 
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.h #1320707:1320708
@@ -90,6 +90,7 @@
     void columnLayoutChanged(int);
     void showBeginning();
     void updateUnitLineEnabled(bool);
+    void updateFrameBuffer(bool);
 
   private:
     const int _index_offset;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320707:1320708
@@ -288,8 +288,13 @@
       delete file;
       return 0;
     }
+
     _fileBuffer.setFile(file);
-    _fileBuffer.read(_reader.rowIndex(), begin, bytesToRead);
+    if (_config._limitFileBuffer && _config._limitFileBufferSize < bytesToRead) {
+      _fileBuffer.readFileSlidingWindow(_reader.rowIndex(), begin, bytesToRead);
+    } else {
+      _fileBuffer.readWholeFile(_reader.rowIndex(), begin, bytesToRead);
+    }
     if (_fileBuffer.bytesRead() == 0) {
       success = false;
       return 0;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisourceconfig.cpp #1320707:1320708
@@ -51,6 +51,10 @@
 const char AsciiSourceConfig::Tag_fieldsLine[] = "fields";
 const char AsciiSourceConfig::Key_unitsLine[] = "Units Line";
 const char AsciiSourceConfig::Tag_unitsLine[] = "units";
+const char AsciiSourceConfig::Key_limitFileBuffer[] = "Limit file buffer size";
+const char AsciiSourceConfig::Tag_limitFileBuffer[] = "limitFileBuffer";
+const char AsciiSourceConfig::Key_limitFileBufferSize[] = "Size of limited file buffer";
+const char AsciiSourceConfig::Tag_limitFileBufferSize[] = "limitFileBufferSize";
 
 AsciiSourceConfig::AsciiSourceConfig() :
   _delimiters(DEFAULT_COMMENT_DELIMITERS),
@@ -66,7 +70,9 @@
   _readUnits(false),
   _fieldsLine(0),
   _unitsLine(0),
-  _useDot(true)
+  _useDot(true),
+  _limitFileBuffer(false),
+  _limitFileBufferSize(128)
 {
 }
 
@@ -87,6 +93,8 @@
   _columnWidthIsConst >> cfg;
   _readUnits >> cfg;
   _unitsLine >> cfg;
+  _limitFileBuffer >> cfg;
+  _limitFileBufferSize >> cfg;
 }
 
 
@@ -118,6 +126,8 @@
   _columnWidthIsConst << cfg;
   _readUnits << cfg;
   _unitsLine << cfg;
+  _limitFileBuffer << cfg;
+  _limitFileBufferSize << cfg;
 }
 
 
@@ -156,6 +166,8 @@
   _columnWidthIsConst >> s;
   _readUnits >> s;
   _unitsLine >> s;
+  _limitFileBuffer >> s;
+  _limitFileBufferSize >> s;
 
   s.writeEndElement();
 }
@@ -176,6 +188,8 @@
   _columnWidthIsConst << attributes;
   _readUnits << attributes;
   _unitsLine << attributes;
+  _limitFileBuffer << attributes;
+  _limitFileBufferSize << attributes;
 }
 
 
@@ -199,6 +213,8 @@
         _columnWidthIsConst << elem;
         _readUnits << elem;
         _unitsLine << elem;
+        _limitFileBuffer << elem;
+        _limitFileBufferSize << elem;
       }
     }
     n = n.nextSibling();
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisourceconfig.h #1320707:1320708
@@ -49,6 +49,10 @@
     static const char Tag_fieldsLine[];
     static const char Key_unitsLine[];
     static const char Tag_unitsLine[];
+    static const char Key_limitFileBuffer[];
+    static const char Tag_limitFileBuffer[];
+    static const char Key_limitFileBufferSize[];
+    static const char Tag_limitFileBufferSize[];
 
   public:
     AsciiSourceConfig();
@@ -78,6 +82,8 @@
     NamedParameter<int, Key_fieldsLine, Tag_fieldsLine> _fieldsLine;
     NamedParameter<int, Key_unitsLine, Tag_unitsLine> _unitsLine;
     NamedParameter<bool, Key_useDot, Tag_useDot> _useDot;
+    NamedParameter<bool, Key_limitFileBuffer, Tag_limitFileBuffer> _limitFileBuffer;
+    NamedParameter<int, Key_limitFileBufferSize, Tag_limitFileBufferSize> _limitFileBufferSize;
 
 
   private:


More information about the Kst mailing list