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

Barth Netterfield netterfield at astro.utoronto.ca
Thu Dec 17 03:36:05 CET 2009


SVN commit 1063132 by netterfield:

BUG: 215931
QImages look at file name extensions before attempting to parse files.
This means that the QImage data source requires recognized extensions
to read a file, but is a lot faster if the file is not an image.

Re-instate the file type label in the data wizard.


 M  +1 -1      datasources/ascii/ascii.cpp  
 M  +21 -16    datasources/qimagesource/qimagesource.cpp  
 M  +7 -10     libkst/datasource.cpp  
 M  +2 -0      libkstapp/datawizard.cpp  
 M  +77 -116   libkstapp/datawizardpagedatasource.ui  


--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.cpp #1063131:1063132
@@ -200,7 +200,7 @@
 AsciiSource::AsciiSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e)
 : Kst::DataSource(store, cfg, filename, type, File), _rowIndex(0L), _config(0L), _tmpBuf(0L), _tmpBufSize(0) {
 
-  TIME_IN_SCOPE(Ctor_AsciiSource);
+  //TIME_IN_SCOPE(Ctor_AsciiSource);
 
   _valid = false;
   _haveHeader = false;
--- branches/work/kst/portto4/kst/src/datasources/qimagesource/qimagesource.cpp #1063131:1063132
@@ -409,30 +409,35 @@
 int QImageSourcePlugin::understands(QSettings *cfg, const QString& filename) const {
   Q_UNUSED(cfg)
 
-  timespec t;
-  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
-  qDebug() << "*** qimage::understands checkpoint A: " << 1.0 * t.tv_sec + 1e-9 * t.tv_nsec;
+  QList<QByteArray> formats = QImageReader::supportedImageFormats();
 
+  bool matches = false;
+  foreach (QByteArray ext, formats) {
+    if (filename.toLower().endsWith(ext.toLower())) {
+      matches = true;
+      break;
+    }
+  }
+  if (!matches) {
+    return 0;
+  }
+
   QString ftype( QImageReader::imageFormat( filename ) );
 
-    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
-  qDebug() << "*** qimage::understands checkpoint B: " << 1.0 * t.tv_sec + 1e-9 * t.tv_nsec;
-
   if ( ftype.isEmpty() ) 
     return 0;
 
-  if ( ftype == "TIFF" ) {
-    if ( !filename.toLower().endsWith(".tif") ) return 0;
-  }
+  //QImageReader is incorrectly identifying some ascii files with
+  // images.  Enforce filenames (may not be needed anymore, since
+  // we already know that the extension matches *some* image format.
 
+  //if ( ftype == "TIFF" ) {
+  //  if ( !filename.toLower().endsWith(".tif") ) return 0;
+  //}
+  //if ( ftype == "pcx" ) {
+  //  if ( !filename.toLower().endsWith(".pcx") ) return 0;
+  //}
 
-  //QImageReader is incorrectly identifying a single column ascii file with
-  // the first row blank as a pcx file... so... enforce filename...
-  if ( ftype == "pcx" ) {
-    if ( !filename.toLower().endsWith(".pcx") ) return 0;
-  }
-
-
   return 90;
 }
 
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #1063131:1063132
@@ -241,16 +241,13 @@
 
   QList<PluginSortContainer> bestPlugins = bestPluginsForSource(filename, type);
 
-  DataSourcePtr plugin = bestPlugins.at(0).plugin->create(store, settingsObject, filename, QString::null, e);
-
-  return plugin;
-
-  //for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
-  //  DataSourcePtr plugin = (*i).plugin->create(store, settingsObject, filename, QString::null, e);
-  //  if (plugin) {
-  //    return plugin;
-  //  }
-  //}
+  // we don't actually iterate here, unless the first plugin fails.  (Not sure this helps at all.)
+  for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
+    DataSourcePtr plugin = (*i).plugin->create(store, settingsObject, filename, QString::null, e);
+    if (plugin) {
+      return plugin;
+    }
+  }
   return 0L;
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #1063131:1063132
@@ -81,6 +81,7 @@
   _pageValid = true;
 
   _dataSource = DataSource::findOrLoadSource(_store, filename);
+  _fileType->setText(_dataSource->fileType());
 
   _dataSource->readLock();
   _configureSource->setEnabled(_dataSource->hasConfigWidget());
@@ -98,6 +99,7 @@
 
 void DataWizardPageDataSource::sourceChanged(const QString& file) {
   _pageValid = false;
+  _fileType->setText(QString());
   _configureSource->setEnabled(false);
   emit completeChanged();
 
--- branches/work/kst/portto4/kst/src/libkstapp/datawizardpagedatasource.ui #1063131:1063132
@@ -1,107 +1,134 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>DataWizardPageDataSource</class>
- <widget class="QWizardPage" name="DataWizardPageDataSource" >
-  <property name="geometry" >
+ <widget class="QWizardPage" name="DataWizardPageDataSource">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>744</width>
-    <height>117</height>
+    <height>190</height>
    </rect>
   </property>
-  <layout class="QGridLayout" >
-   <property name="leftMargin" >
-    <number>0</number>
-   </property>
-   <property name="topMargin" >
-    <number>0</number>
-   </property>
-   <property name="rightMargin" >
-    <number>0</number>
-   </property>
-   <property name="bottomMargin" >
-    <number>0</number>
-   </property>
-   <item row="0" column="0" colspan="3" >
-    <widget class="QLabel" name="textLabel2" >
-     <property name="text" >
-      <string>&lt;p>Please select a &lt;i>data source&lt;/i> to work from.  This will typically be your file containing data points or vectors.&lt;/p></string>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0" colspan="4">
+    <widget class="QLabel" name="textLabel2">
+     <property name="text">
+      <string>&lt;p&gt;Please select a &lt;i&gt;data source&lt;/i&gt; to work from.  This will typically be your file containing data points or vectors.&lt;/p&gt;</string>
      </property>
-     <property name="alignment" >
+     <property name="alignment">
       <set>Qt::AlignTop</set>
      </property>
-     <property name="wordWrap" >
+     <property name="wordWrap">
       <bool>true</bool>
      </property>
     </widget>
    </item>
-   <item row="2" column="2" >
+   <item row="1" column="0" colspan="4">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeType" >
+     <property name="sizeType">
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
-       <width>71</width>
-       <height>21</height>
+       <width>637</width>
+       <height>151</height>
       </size>
      </property>
     </spacer>
    </item>
-   <item row="2" column="0" >
+   <item row="2" column="0">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeType" >
+     <property name="sizeType">
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
-       <width>101</width>
+       <width>71</width>
        <height>21</height>
       </size>
      </property>
     </spacer>
    </item>
-   <item row="2" column="1" >
-     <widget class="Kst::DataSourceSelector" native="1" name="_url" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
+   <item row="3" column="0" colspan="4">
+    <widget class="Kst::DataSourceSelector" name="_url" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
        <horstretch>3</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
+     <property name="minimumSize">
+      <size>
+       <width>0</width>
+       <height>10</height>
+      </size>
+     </property>
     </widget>
    </item>
-   <item row="1" column="1" colspan="2" >
+   <item row="4" column="1">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeType" >
+     <property name="sizeType">
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
-       <width>637</width>
-       <height>151</height>
+       <width>408</width>
+       <height>22</height>
       </size>
      </property>
     </spacer>
    </item>
-   <item row="4" column="1" colspan="2" >
+   <item row="4" column="2">
+    <widget class="QLabel" name="_fileType">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+       <horstretch>10</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string>Unknown File Type</string>
+     </property>
+     <property name="wordWrap">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="3">
+    <widget class="QPushButton" name="_configureSource">
+     <property name="enabled">
+      <bool>false</bool>
+     </property>
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string>Con&amp;figure...</string>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="0" colspan="4">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeType" >
+     <property name="sizeType">
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>637</width>
        <height>151</height>
@@ -109,79 +136,13 @@
      </property>
     </spacer>
    </item>
-   <item row="3" column="1" colspan="2" >
-    <layout class="QHBoxLayout" >
-     <property name="leftMargin" >
-      <number>0</number>
-     </property>
-     <property name="topMargin" >
-      <number>0</number>
-     </property>
-     <property name="rightMargin" >
-      <number>0</number>
-     </property>
-     <property name="bottomMargin" >
-      <number>0</number>
-     </property>
-     <item>
-      <spacer>
-       <property name="orientation" >
-        <enum>Qt::Vertical</enum>
-       </property>
-       <property name="sizeType" >
-        <enum>QSizePolicy::Expanding</enum>
-       </property>
-       <property name="sizeHint" >
-        <size>
-         <width>408</width>
-         <height>22</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QLabel" name="_fileType" >
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
-         <horstretch>10</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="wordWrap" >
-        <bool>false</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QPushButton" name="_configureSource" >
-       <property name="enabled" >
-        <bool>false</bool>
-       </property>
-       <property name="sizePolicy" >
-        <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="text" >
-        <string>Con&amp;figure...</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
   </layout>
  </widget>
- <layoutdefault spacing="6" margin="11" />
+ <layoutdefault spacing="6" margin="11"/>
  <customwidgets>
   <customwidget>
-   <class>QWizardPage</class>
+   <class>Kst::DataSourceSelector</class>
    <extends>QWidget</extends>
-   <header>qwizardpage.h</header>
-  </customwidget>
-  <customwidget>
-    <class>Kst::DataSourceSelector</class>
-   <extends>QWidget</extends>
    <header>datasourceselector.h</header>
   </customwidget>
  </customwidgets>


More information about the Kst mailing list