[QGIS Commit] r9639 -
branches/advanced_printing_branch2/src/app/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Nov 15 05:29:31 EST 2008
Author: mhugent
Date: 2008-11-15 05:29:31 -0500 (Sat, 15 Nov 2008)
New Revision: 9639
Modified:
branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.cpp
branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.h
Log:
Improvements 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-15 06:10:32 UTC (rev 9638)
+++ branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.cpp 2008-11-15 10:29:31 UTC (rev 9639)
@@ -234,46 +234,59 @@
QFileInfoList::const_iterator fileIt = fileList.constBegin();
QProgressDialog progress("Adding Icons...", "Abort", 0, fileList.size() - 1, this);
- progress.setWindowModality(Qt::WindowModal);
+ //cancel button does not seem to work properly with modal dialog
+ //progress.setWindowModality(Qt::WindowModal);
int counter = 0;
for(; fileIt != fileList.constEnd(); ++fileIt)
{
+
progress.setLabelText(tr("Creating icon for file ") + fileIt->fileName());
- QCoreApplication::processEvents(); //for abort button
+ progress.setValue(counter);
+ QCoreApplication::processEvents();
if(progress.wasCanceled())
{
break;
}
- progress.setValue(counter);
QString filePath = fileIt->absoluteFilePath();
- //exclude non-picture files
- if(!testPictureFile(filePath))
+ //test if file is svg or pixel format
+ bool fileIsPixel = false;
+ bool fileIsSvg = testSvgFile(filePath);
+ if(!fileIsSvg)
+ {
+ fileIsPixel = testImageFile(filePath);
+ }
+
+ //exclude files that are not svg or image
+ if(!fileIsSvg && !fileIsPixel)
{
- ++counter;
- continue;
+ ++counter; continue;
}
QListWidgetItem * listItem = new QListWidgetItem(mPreviewListWidget);
- if(filePath.endsWith(".svg")) //for svg files: create the icon directly
+ if(fileIsSvg)
{
QIcon icon(filePath);
listItem->setIcon(icon);
}
- else //for pixel formats: create icon from scaled pixmap
+ else if(fileIsPixel) //for pixel formats: create icon from scaled pixmap
{
QPixmap iconPixmap(filePath);
if(iconPixmap.isNull())
{
- continue; //unknown file format or other problem
+ ++counter; continue; //unknown file format or other problem
}
//set pixmap hardcoded to 30/30, same as icon size for mPreviewListWidget
QPixmap scaledPixmap(iconPixmap.scaled(QSize(30, 30), Qt::KeepAspectRatio));
QIcon icon(scaledPixmap);
listItem->setIcon(icon);
}
+ else
+ {
+ ++counter; continue;
+ }
listItem->setText( "" );
//store the absolute icon file path as user data
@@ -297,7 +310,6 @@
QFileInfoList::const_iterator dirIt = directoryList.constBegin();
for(; dirIt != directoryList.constEnd(); ++dirIt)
{
- qWarning(dirIt->absoluteFilePath().toLocal8Bit().data());
if(addDirectoryToPreview(dirIt->absoluteFilePath()) == 0)
{
mSearchDirectoriesComboBox->addItem(dirIt->absoluteFilePath());
@@ -305,23 +317,22 @@
}
}
-bool QgsComposerPictureWidget::testPictureFile(const QString& filename) const
+bool QgsComposerPictureWidget::testSvgFile(const QString& filename) const
{
- bool pixelFormat = false;
- bool svgFormat = false;
+ QSvgRenderer svgRenderer(filename);
+ if(svgRenderer.isValid())
+ {
+ return true;
+ }
+ return false;
+}
+bool QgsComposerPictureWidget::testImageFile(const QString& filename) const
+{
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-15 06:10:32 UTC (rev 9638)
+++ branches/advanced_printing_branch2/src/app/composer/qgscomposerpicturewidget.h 2008-11-15 10:29:31 UTC (rev 9639)
@@ -51,8 +51,10 @@
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;
+ /**Tests if a file is valid svg*/
+ bool testSvgFile(const QString& filename) const;
+ /**Tests if a file is a valid pixel format*/
+ bool testImageFile(const QString& filename) const;
};
#endif
More information about the QGIS-commit
mailing list