-
-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always track file-based layers in QFieldCloud #5118
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,6 +24,8 @@ | |||||
#include <QString> | ||||||
#include <qgsapplication.h> | ||||||
#include <qgsmessagelog.h> | ||||||
#include <qgsprovidermetadata.h> | ||||||
#include <qgsproviderregistry.h> | ||||||
|
||||||
static QString sLocalCloudDirectory; | ||||||
|
||||||
|
@@ -58,11 +60,52 @@ bool QFieldCloudUtils::isCloudAction( const QgsMapLayer *layer ) | |||||
|
||||||
const QString layerAction( layer->customProperty( QStringLiteral( "QFieldSync/cloud_action" ) ).toString().toUpper() ); | ||||||
|
||||||
if ( layerAction == QStringLiteral( "NO_ACTION" ) || layerAction == QStringLiteral( "REMOVE" ) ) | ||||||
return false; | ||||||
if ( isFileBasedLayer( layer ) ) | ||||||
{ | ||||||
if ( layerAction == QStringLiteral( "REMOVE" ) ) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
} | ||||||
else | ||||||
{ | ||||||
if ( layerAction == QStringLiteral( "NO_ACTION" ) || layerAction == QStringLiteral( "REMOVE" ) ) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
} | ||||||
|
||||||
return true; | ||||||
} | ||||||
|
||||||
bool QFieldCloudUtils::isFileBasedLayer( const QgsMapLayer *layer ) | ||||||
{ | ||||||
if ( layer->type() == Qgis::LayerType::VectorTile ) | ||||||
{ | ||||||
QgsDataSourceUri uri; | ||||||
uri.setEncodedUri( layer->source() ); | ||||||
return QFile::exists( uri.param( "url" ) ); | ||||||
} | ||||||
|
||||||
if ( !layer->dataProvider() ) | ||||||
{ | ||||||
return false; | ||||||
} | ||||||
|
||||||
QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( layer->dataProvider()->name() ); | ||||||
QVariantMap metadata = providerMetadata->decodeUri( layer->source() ); | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: variable 'metadata' of type 'QVariantMap' (aka 'QMap<QString, QVariant>') can be declared 'const' [misc-const-correctness]
Suggested change
|
||||||
const QString filename = metadata.value( QStringLiteral( "path" ), QString() ).toString(); | ||||||
const QString resolvedFilename = QgsProject::instance()->pathResolver().writePath( filename ); | ||||||
|
||||||
if ( resolvedFilename.startsWith( QStringLiteral( "localized:" ) ) ) | ||||||
suricactus marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{ | ||||||
return QFile::exists( resolvedFilename.mid( 10 ) ); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: 10 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers] return QFile::exists( resolvedFilename.mid( 10 ) );
^ |
||||||
|
||||||
return QFile::exists( filename ); | ||||||
} | ||||||
|
||||||
const QString QFieldCloudUtils::getProjectId( const QString &fileName ) | ||||||
{ | ||||||
QFileInfo fi( fileName ); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,14 @@ class QFieldCloudUtils : public QObject | |
*/ | ||
static bool isCloudAction( const QgsMapLayer *layer ); | ||
|
||
/** | ||
* Returns if the \layer is file-based or online layer. | ||
suricactus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param layer to be checked | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'username' has public visibility [misc-non-private-member-variables-in-classes] QString username;
^ |
||
* @return const bool true if the layer is file-based | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: member variable 'email' has public visibility [misc-non-private-member-variables-in-classes] QString email;
^ |
||
*/ | ||
static bool isFileBasedLayer( const QgsMapLayer *layer ); | ||
|
||
/** | ||
* Returns the cloud project id. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: implicit conversion 'const QgsDataProvider *' -> bool [readability-implicit-bool-conversion]