[QGIS Commit] r9590 - branches/advanced_printing_branch2/src/app/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Nov 8 05:51:48 EST 2008


Author: mhugent
Date: 2008-11-08 05:51:48 -0500 (Sat, 08 Nov 2008)
New Revision: 9590

Modified:
   branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.cpp
   branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.h
Log:
test file formats for composer picture preview

Modified: branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.cpp
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.cpp	2008-11-08 10:47:50 UTC (rev 9589)
+++ branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.cpp	2008-11-08 10:51:48 UTC (rev 9590)
@@ -22,7 +22,9 @@
 #include <QDoubleValidator>
 #include <QFileDialog>
 #include <QFileInfo>
+#include <QImageReader>
 #include <QMessageBox>
+#include <QSvgRenderer>
 
 QgsComposerPictureWidget::QgsComposerPictureWidget( QgsComposerPicture* picture ): QWidget(), mPicture( picture )
 {
@@ -228,8 +230,15 @@
   QFileInfoList::const_iterator fileIt = fileList.constBegin();
   for(; fileIt != fileList.constEnd(); ++fileIt)
   {
-    qWarning(fileIt->absoluteFilePath().toLocal8Bit().data());
-    QIcon icon(fileIt->absoluteFilePath()); //does this work with svg icons?
+    QString filePath = fileIt->absoluteFilePath();
+
+    //exclude non-picture files
+    if(!testPictureFile(filePath))
+    {
+      return 2;
+    }
+
+    QIcon icon(filePath);
     QListWidgetItem * listItem = new QListWidgetItem(mPreviewListWidget);
     listItem->setIcon( icon );
     listItem->setText( "" );
@@ -260,3 +269,24 @@
     }
   }
 }
+
+bool QgsComposerPictureWidget::testPictureFile(const QString& filename) const
+{
+  bool pixelFormat = false;
+  bool svgFormat = false;
+
+  QString formatName = QString(QImageReader::imageFormat(filename));
+  qWarning(formatName.toLocal8Bit().data());
+  if(!formatName.isEmpty())
+  {
+    return true; //file is in a supported pixel format
+  }
+
+  QSvgRenderer svgRenderer(filename);
+  if(svgRenderer.isValid())
+  {
+    return true;
+  }
+
+  return false;
+}

Modified: branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.h
===================================================================
--- branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.h	2008-11-08 10:47:50 UTC (rev 9589)
+++ branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.h	2008-11-08 10:51:48 UTC (rev 9590)
@@ -51,6 +51,8 @@
     int addDirectoryToPreview(const QString& path);
     /**Add the icons of the standard directories to the preview*/
     void addStandardDirectoriesToPreview();
+    /**Returns true if a file is in a supported image format or in svg*/
+    bool testPictureFile(const QString& filename) const;
 };
 
 #endif



More information about the QGIS-commit mailing list