# HG changeset patch # User Roeland Merks # Date 2010-11-26 14:56:40 # Node ID d7edbe56b125060b651b2c5ec547cc0cf320d6bc # Parent da350435dfe3d28b80dcd4af9c9d6f2b89b4dabc The snapshot feature stopped working on Windows. The problem was in MainBase::Save, where the "format" argument was added to "image->save". On Windows the file format must be given in Capitals and in specific formats (e.g. TIFF works, TIF not). It is much safer to leave the 'format' argument out and let the system guess the format from the file extension. -- user: Roeland Merks branch 'default' changed src/canvas.cpp changed src/mainbase.cpp changed src/mainbase.h diff --git a/src/canvas.cpp b/src/canvas.cpp --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -718,7 +718,7 @@ void Main::snapshot() Q3FileDialog *fd = new Q3FileDialog( this, "Save snapshot", TRUE ); fd->setDir(par.datadir); fd->setMode( Q3FileDialog::AnyFile ); - fd->setFilter( "Image files (*.pdf *.png *.jpg *.tif *.bpm)"); + fd->setFilter( "Image files (*.pdf *.png *.jpg *.tif)"); QString fileName; if ( fd->exec() == QDialog::Accepted ) { @@ -750,8 +750,12 @@ void Main::snapshot() } else { // Save bitmaps at 1024x768 - Save((const char *)fileName, extension, 1024, 768); - QString status_message = QString("Wrote snapshot to %1").arg(fileName); + QString status_message; + if (Save((const char *)fileName, extension, 1024, 768)==0) { + status_message = QString("Wrote snapshot to %1").arg(fileName); + } else { + status_message = QString("Error writing snapshot to %1").arg(fileName); + } cerr << status_message.toStdString() << endl; statusBar()->showMessage(status_message); diff --git a/src/mainbase.cpp b/src/mainbase.cpp --- a/src/mainbase.cpp +++ b/src/mainbase.cpp @@ -319,7 +319,7 @@ void MainBase::XMLReadSettings(xmlNode * } } -void MainBase::Save(const char *fname, const char *format, int sizex, int sizey) +int MainBase::Save(const char *fname, const char *format, int sizex, int sizey) { Vector ll,ur; @@ -327,15 +327,15 @@ void MainBase::Save(const char *fname, c if (QString(fname).isEmpty()) { MyWarning::warning("No output filename given. Saving nothing.\n"); - return; + return 1; } ll*=Cell::Magnification(); ur*=Cell::Magnification(); // give the leaf some space Vector border = ((ur-ll)/5.); - - if (!QString(format).contains("pdf", Qt::CaseInsensitive)) { + + if (!QString(format).contains("PDF", Qt::CaseInsensitive)) { QImage *image = new QImage(QSize(sizex, sizey), QImage::Format_RGB32); image->fill(QColor(Qt::white).rgb()); @@ -344,9 +344,12 @@ void MainBase::Save(const char *fname, c #ifdef QDEBUG qDebug() << "Native Image Filename: " << QDir::toNativeSeparators(QString(fname)) << endl; #endif - if (!image->save(QDir::toNativeSeparators(QString(fname)), format)) { - MyWarning::warning("Image not saved successfully. Is the disk full or the extension not recognized?"); - } + if (!image->save(QDir::toNativeSeparators(QString(fname)))) { // please do not add "format" here! It is much better to have the system guess the file format from the extension. That prevents loads of cross-platform problems. + MyWarning::warning("Image '%s' not saved successfully. Is the disk full or the extension not recognized?",fname); + delete painter; + delete image; + return 1; + } delete painter; delete image; } else { @@ -358,6 +361,7 @@ void MainBase::Save(const char *fname, c cerr << "Rendering to printer\n"; } + return 0; } void MainBase::CutSAM() diff --git a/src/mainbase.h b/src/mainbase.h --- a/src/mainbase.h +++ b/src/mainbase.h @@ -96,7 +96,7 @@ class MainBase { virtual double getFluxArrowsize(void) { return 10.;} - void Save(const char *fname, const char *format, int sizex=640, int sizey=480); + int Save(const char *fname, const char *format, int sizex=640, int sizey=480); void CutSAM(void); void Plot(int resize_stride=10);