Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/layerobserver.cpp
Expand Up @@ -311,9 +311,9 @@ void LayerObserver::addLayerListeners()
continue;
}

qInfo() << "LayerObserver::addLayerListeners: vl->getLocalPkAttribute()=" << DeltaFileWrapper::getLocalPkAttribute( vl );
qInfo() << "LayerObserver::addLayerListeners: vl->getSourcePkAttribute()=" << DeltaFileWrapper::getSourcePkAttribute( vl );
qInfo() << "LayerObserver::addLayerListeners: vl->customProperties()=" << vl->customProperties().keys();
qInfo() << "LayerObserver::addLayerListeners: " << layer->name() << "; vl->getLocalPkAttribute()=" << DeltaFileWrapper::getLocalPkAttribute( vl );
qInfo() << "LayerObserver::addLayerListeners: " << layer->name() << "; vl->getSourcePkAttribute()=" << DeltaFileWrapper::getSourcePkAttribute( vl );
qInfo() << "LayerObserver::addLayerListeners: " << layer->name() << "; vl->customProperties()=" << vl->customProperties().keys();

disconnect( vl, &QgsVectorLayer::beforeCommitChanges, this, &LayerObserver::onBeforeCommitChanges );
disconnect( vl, &QgsVectorLayer::committedFeaturesAdded, this, &LayerObserver::onCommittedFeaturesAdded );
Expand Down
47 changes: 45 additions & 2 deletions src/core/utils/qfieldcloudutils.cpp
Expand Up @@ -24,6 +24,8 @@
#include <QString>
#include <qgsapplication.h>
#include <qgsmessagelog.h>
#include <qgsprovidermetadata.h>
#include <qgsproviderregistry.h>

static QString sLocalCloudDirectory;

Expand Down Expand Up @@ -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() )
{
Copy link
Contributor

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]

Suggested change
{
if ( layer->dataProvider() == nullptr )

return false;
}

QgsProviderMetadata *providerMetadata = QgsProviderRegistry::instance()->providerMetadata( layer->dataProvider()->name() );
QVariantMap metadata = providerMetadata->decodeUri( layer->source() );

Copy link
Contributor

Choose a reason for hiding this comment

The 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
QVariantMap const metadata = providerMetadata->decodeUri( layer->source() );

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 ) );
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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 );
Expand Down
8 changes: 8 additions & 0 deletions src/core/utils/qfieldcloudutils.h
Expand Up @@ -52,6 +52,14 @@ class QFieldCloudUtils : public QObject
*/
static bool isCloudAction( const QgsMapLayer *layer );

/**
* Returns if the \a layer is a file-based or a remote layer.
*
* @param layer to be checked
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
*
Expand Down