Skip to content
Permalink
Browse files

[FEATURE] Add an option to set the default project file format (qgs/q…

…gz) (#33872)
  • Loading branch information
3nids committed Jan 17, 2020
1 parent 5af1306 commit 18a7cd065955e8f034f15b82c38793bf09f4e539
@@ -0,0 +1,14 @@
# The following has been generated automatically from src/core/qgsproject.h
# monkey patching scoped based enum
QgsProject.FlagDontResolveLayers = QgsProject.ReadFlag.FlagDontResolveLayers
QgsProject.ReadFlag.FlagDontResolveLayers.__doc__ = "Don't resolve layer paths (i.e. don't load any layer content). Dramatically improves project read time if the actual data from the layers is not required."
QgsProject.FlagDontLoadLayouts = QgsProject.ReadFlag.FlagDontLoadLayouts
QgsProject.ReadFlag.FlagDontLoadLayouts.__doc__ = "Don't load print layouts. Improves project read time if layouts are not required, and allows projects to be safely read in background threads (since print layouts are not thread safe)."
QgsProject.ReadFlag.__doc__ = 'Flags which control project read behavior.\n\n.. versionadded:: 3.10\n\n' + '* ``FlagDontResolveLayers``: ' + QgsProject.ReadFlag.FlagDontResolveLayers.__doc__ + '\n' + '* ``FlagDontLoadLayouts``: ' + QgsProject.ReadFlag.FlagDontLoadLayouts.__doc__
# --
# monkey patching scoped based enum
QgsProject.FileFormat.Qgz.__doc__ = "Archive file format, supports auxiliary data"
QgsProject.FileFormat.Qgs.__doc__ = "Project saved in a clear text, does not support auxiliary data"
QgsProject.FileFormat.__doc__ = 'Flags which control project read behavior.\n\n.. versionadded:: 3.12\n\n' + '* ``Qgz``: ' + QgsProject.FileFormat.Qgz.__doc__ + '\n' + '* ``Qgs``: ' + QgsProject.FileFormat.Qgs.__doc__
# --
QgsProject.FileFormat.baseClass = QgsProject
@@ -33,6 +33,21 @@ open within the main QGIS application.
#include "qgsproject.h"
%End
public:

enum class ReadFlag
{
FlagDontResolveLayers,
FlagDontLoadLayouts,
};
typedef QFlags<QgsProject::ReadFlag> ReadFlags;


enum class FileFormat
{
Qgz,
Qgs,
};

static QgsProject *instance();
%Docstring
Returns the QgsProject singleton instance
@@ -235,14 +250,6 @@ Clears the project, removing all settings and resetting it back to an empty, def
.. versionadded:: 2.4
%End

enum ReadFlag
{
FlagDontResolveLayers,
FlagDontLoadLayouts,
};
typedef QFlags<QgsProject::ReadFlag> ReadFlags;


bool read( const QString &filename, QgsProject::ReadFlags flags = 0 );
%Docstring
Reads given project file from the given file.
@@ -203,7 +203,7 @@ QVariantMap QgsStyleFromProjectAlgorithm::processAlgorithm( const QVariantMap &p
{
// load project from path
QgsProject p;
if ( !p.read( mProjectPath, QgsProject::FlagDontResolveLayers ) )
if ( !p.read( mProjectPath, QgsProject::ReadFlag::FlagDontResolveLayers ) )
{
throw QgsProcessingException( QObject::tr( "Could not read project %1" ).arg( mProjectPath ) );
}
@@ -643,7 +643,7 @@ void QgsProjectItemGuiProvider::populateContextMenu( QgsDataItem *item, QMenu *m

QgsProject p;
QgsTemporaryCursorOverride override( Qt::WaitCursor );
if ( p.read( projectPath, QgsProject::FlagDontResolveLayers ) )
if ( p.read( projectPath, QgsProject::ReadFlag::FlagDontResolveLayers ) )
{
p.accept( &visitor );
override.release();
@@ -6666,12 +6666,23 @@ bool QgisApp::fileSave()

const QString qgsExt = tr( "QGIS files" ) + " (*.qgs)";
const QString zipExt = tr( "QGZ files" ) + " (*.qgz)";

QString exts;
QgsProject::FileFormat defaultProjectFileFormat = settings.enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), QgsProject::FileFormat::Qgz );
if ( defaultProjectFileFormat == QgsProject::FileFormat::Qgs )
{
exts = qgsExt + QStringLiteral( ";;" ) + zipExt;
}
else
{
exts = zipExt + QStringLiteral( ";;" ) + qgsExt;
}
QString filter;
QString path = QFileDialog::getSaveFileName(
this,
tr( "Choose a QGIS project file" ),
lastUsedDir + '/' + QgsProject::instance()->title(),
zipExt + ";;" + qgsExt, &filter );
exts, &filter );
if ( path.isEmpty() )
return false;

@@ -473,7 +473,7 @@ QVector<QgsDataItem *> QgsProjectRootDataItem::createChildren()
QVector<QgsDataItem *> childItems;

QgsProject p;
if ( !p.read( mPath, QgsProject::FlagDontResolveLayers | QgsProject::FlagDontLoadLayouts ) )
if ( !p.read( mPath, QgsProject::ReadFlag::FlagDontResolveLayers | QgsProject::ReadFlag::FlagDontLoadLayouts ) )
{
childItems.append( new QgsErrorItem( nullptr, p.error(), mPath + "/error" ) );
return childItems;
@@ -776,6 +776,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
Qgis::PythonMacroMode pyMacroMode = mSettings->enumValue( QStringLiteral( "/qgis/enableMacros" ), Qgis::PythonMacroMode::Ask );
mEnableMacrosComboBox->setCurrentIndex( mEnableMacrosComboBox->findData( QVariant::fromValue( pyMacroMode ) ) );

QgsProject::FileFormat defaultProjectFileFormat = mSettings->enumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), QgsProject::FileFormat::Qgz );
mFileFormatQgzButton->setChecked( defaultProjectFileFormat == QgsProject::FileFormat::Qgz );
mFileFormatQgsButton->setChecked( defaultProjectFileFormat == QgsProject::FileFormat::Qgs );

// templates
cbxProjectDefaultNew->setChecked( mSettings->value( QStringLiteral( "/qgis/newProjectDefault" ), QVariant( false ) ).toBool() );
QString templateDirName = mSettings->value( QStringLiteral( "/qgis/projectTemplateDir" ),
@@ -1544,6 +1548,8 @@ void QgsOptions::saveOptions()
}
mSettings->setEnumValue( QStringLiteral( "/qgis/enableMacros" ), mEnableMacrosComboBox->currentData().value<Qgis::PythonMacroMode>() );

mSettings->setEnumValue( QStringLiteral( "/qgis/defaultProjectFileFormat" ), mFileFormatQgsButton->isChecked() ? QgsProject::FileFormat::Qgs : QgsProject::FileFormat::Qgz );

QgsApplication::setNullRepresentation( leNullValue->text() );
mSettings->setValue( QStringLiteral( "/qgis/style" ), cmbStyle->currentText() );
mSettings->setValue( QStringLiteral( "/qgis/iconSize" ), cmbIconSize->currentText() );
@@ -1046,12 +1046,12 @@ bool QgsProject::addLayer( const QDomElement &layerElem, QList<QDomNode> &broken

// have the layer restore state that is stored in Dom node
QgsMapLayer::ReadFlags layerFlags = nullptr;
if ( flags & QgsProject::FlagDontResolveLayers )
if ( flags & QgsProject::ReadFlag::FlagDontResolveLayers )
layerFlags |= QgsMapLayer::FlagDontResolveLayers;
bool layerIsValid = mapLayer->readLayerXml( layerElem, context, layerFlags ) && mapLayer->isValid();
QList<QgsMapLayer *> newLayers;
newLayers << mapLayer.get();
if ( layerIsValid || flags & QgsProject::FlagDontResolveLayers )
if ( layerIsValid || flags & QgsProject::ReadFlag::FlagDontResolveLayers )
{
emit readMapLayer( mapLayer.get(), layerElem );
addMapLayers( newLayers );
@@ -1472,7 +1472,7 @@ bool QgsProject::readProjectFile( const QString &filename, QgsProject::ReadFlags
emit labelingEngineSettingsChanged();

mAnnotationManager->readXml( doc->documentElement(), context );
if ( !( flags & QgsProject::FlagDontLoadLayouts ) )
if ( !( flags & QgsProject::ReadFlag::FlagDontLoadLayouts ) )
mLayoutManager->readXml( doc->documentElement(), *doc );
mBookmarkManager->readXml( doc->documentElement(), *doc );

@@ -106,6 +106,29 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
Q_PROPERTY( QColor selectionColor READ selectionColor WRITE setSelectionColor NOTIFY selectionColorChanged )

public:

/**
* Flags which control project read behavior.
* \since QGIS 3.10
*/
enum class ReadFlag SIP_MONKEYPATCH_SCOPEENUM
{
FlagDontResolveLayers = 1 << 0, //!< Don't resolve layer paths (i.e. don't load any layer content). Dramatically improves project read time if the actual data from the layers is not required.
FlagDontLoadLayouts = 1 << 1, //!< Don't load print layouts. Improves project read time if layouts are not required, and allows projects to be safely read in background threads (since print layouts are not thread safe).
};
Q_DECLARE_FLAGS( ReadFlags, ReadFlag )

/**
* Flags which control project read behavior.
* \since QGIS 3.12
*/
enum class FileFormat
{
Qgz, //!< Archive file format, supports auxiliary data
Qgs, //!< Project saved in a clear text, does not support auxiliary data
};
Q_ENUM( FileFormat )

//! Returns the QgsProject singleton instance
static QgsProject *instance();

@@ -269,17 +292,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
void clear();

/**
* Flags which control project read behavior.
* \since QGIS 3.10
*/
enum ReadFlag
{
FlagDontResolveLayers = 1 << 0, //!< Don't resolve layer paths (i.e. don't load any layer content). Dramatically improves project read time if the actual data from the layers is not required.
FlagDontLoadLayouts = 1 << 1, //!< Don't load print layouts. Improves project read time if layouts are not required, and allows projects to be safely read in background threads (since print layouts are not thread safe).
};
Q_DECLARE_FLAGS( ReadFlags, ReadFlag )

/**
* Reads given project file from the given file.
* \param filename name of project file to read

0 comments on commit 18a7cd0

Please sign in to comment.
You can’t perform that action at this time.