void QgsVectorLayerProperties::on_pbnSaveStyleAs_clicked() { QSettings myQSettings; // where we keep last used filter in persistant state QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString(); //create a file dialog std::auto_ptr < QFileDialog > myFileDialog ( new QFileDialog( this, QFileDialog::tr( "Save layer properties as style file (.qml)" ), myLastUsedDir, tr( "QGIS Layer Style File (*.qml)" ) ) ); myFileDialog->setFileMode( QFileDialog::AnyFile ); myFileDialog->setAcceptMode( QFileDialog::AcceptSave ); //prompt the user for a file name QString myOutputFileName; if ( myFileDialog->exec() == QDialog::Accepted ) { QStringList myFiles = myFileDialog->selectedFiles(); if ( !myFiles.isEmpty() ) { myOutputFileName = myFiles[0]; } } if ( !myOutputFileName.isEmpty() ) { if ( myFileDialog->selectedFilter() == tr( "QGIS Layer Style File (*.qml)" ) ) { apply(); // make sure the qml to save is uptodate //ensure the user never ommitted the extension from the file name if ( !myOutputFileName.endsWith( ".qml", Qt::CaseInsensitive ) ) { myOutputFileName += ".qml"; } bool defaultLoadedFlag = false; QString myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag ); //reset if the default style was loaded ok only if ( defaultLoadedFlag ) { reset(); } else { //let the user know what went wrong QMessageBox::information( this, tr( "Saved Style" ), myMessage ); } } else { QMessageBox::warning( this, tr( "QGIS" ), tr( "Unknown style format: " ) + myFileDialog->selectedFilter() ); } myQSettings.setValue( "style/lastStyleDir", myFileDialog->directory().absolutePath() ); } }
bool CProjectSettings::CloseProjectSettings() { // check bool if settings have changed if ( IsChangedSinceLastSave ) { // popup to ask if save - yes/no/(cancel) int answer = AfxMessageBox( "Do you want to save the changes in the project?", MB_YESNOCANCEL ); // do what the user clicked if (answer == IDCANCEL) { // Cancel: we dont want to do anything... return FALSE; } else if ( answer == IDYES ) { // get the filename StdString fileName = getSaveFileName(); // check if it is a valid path if ( fileName.length() == 0 ) { // Selecting a file StdString typeExtension( _T("gdsprj") ); StdString filterStr = "GDS project files (*." + typeExtension + ")|*." + typeExtension + "||"; CFileDialog myFileDialog(FALSE, typeExtension, NULL, OFN_ENABLESIZING|OFN_EXPLORER|OFN_OVERWRITEPROMPT, filterStr); // set the file selector default dir to project dir myFileDialog.m_ofn.lpstrInitialDir = GetDirectory(); // Adding it to the listBox if ( myFileDialog.DoModal() == IDOK ) { // get the selected file with path fileName = myFileDialog.GetPathName(); // saving the filename in the object as well setSaveFileName( fileName ); } else { // the user clicked cancel: exiting save dialog return FALSE; } } // send message to make projectloader serialize us. CHashString hszProjectLoader(_T("CProjectLoadSave")); CHashString hszNewParticleSaveFilepath( fileName ); static DWORD msgHash_SaveFile = CHashString(_T("SaveFile")).GetUniqueID(); DWORD result = EngineGetToolBox()->SendMessage(msgHash_SaveFile, sizeof(TCHAR *), (void *)hszNewParticleSaveFilepath.GetString(), 0, &hszProjectLoader); // mark settings as saved IsChangedSinceLastSave = FALSE; } else { // we are here, if the user clicked NO SAVE // then we don't save anything, but return TRUE // that will lead to close GDS return TRUE; } } // Closing project destroys consistency SetSettingsStateConsistency( FALSE ); return TRUE; }
void QuickPrintGui::on_buttonBox_accepted() { writeSettings(); QSettings mySettings; // where we keep last used filter in persistant state QString myLastUsedDir = mySettings.value( "quickprint/lastSaveAsPdfDir", "." ).toString(); //create a file dialog std::auto_ptr < QFileDialog > myFileDialog ( new QFileDialog( this, QFileDialog::tr( "Save experiment report to portable document format (.pdf)" ), myLastUsedDir, tr( "Portable Document Format (*.pdf)" ) ) ); myFileDialog->setFileMode( QFileDialog::AnyFile ); myFileDialog->setAcceptMode( QFileDialog::AcceptSave ); //prompt the user for a file name QString myOutputFileName; if ( myFileDialog->exec() == QDialog::Accepted ) { QStringList myFiles = myFileDialog->selectedFiles(); if ( !myFiles.isEmpty() ) { myOutputFileName = myFiles[0]; } } if ( !myOutputFileName.isEmpty() ) { if ( myFileDialog->selectedFilter() == tr( "Portable Document Format (*.pdf)" ) ) { //ensure the user never omitted the extension from the file name if ( !myOutputFileName.toUpper().endsWith( ".PDF" ) ) { myOutputFileName += ".pdf"; } // call plugin print method here QString myNorthArrowFile = QgsApplication::pkgDataPath() + "/svg/north_arrows/default.svg"; QgsQuickPrint myQuickPrint; myQuickPrint.setMapCanvas( mpMapCanvas ); myQuickPrint.setTitle( leMapTitle->text() ); myQuickPrint.setName( leMapName->text() ); myQuickPrint.setCopyright( teCopyright->toPlainText() ); myQuickPrint.setLogo1( QgsApplication::iconsPath() + "/qgis-icon.png" ); myQuickPrint.setNorthArrow( myNorthArrowFile ); myQuickPrint.setOutputPdf( myOutputFileName ); QString myPageSizeString = cboPageSize->itemData( cboPageSize->currentIndex() ).toString(); myQuickPrint.setPageSize( QgsQuickPrint::stringToPageSize( myPageSizeString ) ); qDebug( "Page size : %s", myPageSizeString.toLocal8Bit().constData() ); myQuickPrint.printMap(); } else { QMessageBox::warning( this, tr( "quickprint" ), tr( "Unknown format: " ) + myFileDialog->selectedFilter() ); } mySettings.setValue( "quickprint/lastSaveAsPdfDir", myFileDialog->directory().absolutePath() ); } //close the dialog accept(); }