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

Implement a default print layout when none available #5993

Merged
merged 7 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified resources/sample_projects/bees.qgz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/sample_projects/datasets/qgep_reach.gpkg
Binary file not shown.
Binary file not shown.
Binary file modified resources/sample_projects/live_qfield_users_survey.qgs.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/sample_projects/wastewater.qgz
Binary file not shown.
Binary file modified resources/sample_projects/wastewater.qgz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
572 changes: 572 additions & 0 deletions resources/templates/layout.qpt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/core/processing/processingalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ bool ProcessingAlgorithm::run( bool previewMode )
-1,
Qgis::ProcessingFeatureSourceDefinitionFlags(),
Qgis::InvalidGeometryCheck(),
QStringLiteral( "$id IN (%1)" ).arg( featureIds.join( ',' ) ) );
QStringLiteral( "@id IN (%1)" ).arg( featureIds.join( ',' ) ) );
parameters[QStringLiteral( "OUTPUT" )] = QStringLiteral( "memory:" );

if ( !previewMode )
Expand Down Expand Up @@ -273,7 +273,7 @@ bool ProcessingAlgorithm::run( bool previewMode )
-1,
Qgis::ProcessingFeatureSourceDefinitionFlags(),
Qgis::InvalidGeometryCheck(),
QStringLiteral( "$id IN (%1)" ).arg( featureIds.join( ',' ) ) );
QStringLiteral( "@id IN (%1)" ).arg( featureIds.join( ',' ) ) );
parameters[QStringLiteral( "OUTPUT" )] = QStringLiteral( "memory:" );

bool ok;
Expand Down
40 changes: 35 additions & 5 deletions src/core/qgismobileapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
#include <qgslayertreeregistrybridge.h>
#include <qgslayoutatlas.h>
#include <qgslayoutexporter.h>
#include <qgslayoutitemlabel.h>
#include <qgslayoutitemmap.h>
#include <qgslayoutmanager.h>
#include <qgslayoutpagecollection.h>
Expand Down Expand Up @@ -1029,6 +1030,7 @@ void QgisMobileapp::readProjectFile()
mProject->setCrs( crs );
mProject->setEllipsoid( crs.ellipsoidAcronym() );
mProject->setTitle( mProjectFileName );
mProject->setPresetHomePath( fi.absolutePath() );
mProject->writeEntry( QStringLiteral( "QField" ), QStringLiteral( "isDataset" ), true );

for ( QgsMapLayer *l : std::as_const( rasterLayers ) )
Expand Down Expand Up @@ -1245,12 +1247,40 @@ bool QgisMobileapp::print( const QString &layoutName )
{
const QList<QgsPrintLayout *> printLayouts = mProject->layoutManager()->printLayouts();
QgsPrintLayout *layoutToPrint = nullptr;
for ( QgsPrintLayout *layout : printLayouts )
std::unique_ptr<QgsPrintLayout> templateLayout;
if ( layoutName.isEmpty() && printLayouts.isEmpty() )
{
if ( layout->name() == layoutName )
QFile templateFile( QStringLiteral( "%1/qfield/templates/layout.qpt" ).arg( PlatformUtilities::instance()->systemSharedDataLocation() ) );
QDomDocument templateDoc;
templateDoc.setContent( &templateFile );

templateLayout = std::make_unique<QgsPrintLayout>( QgsProject::instance() );
bool loadedOK = false;
QList<QgsLayoutItem *> items = templateLayout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOK );
if ( !loadedOK )
{
layoutToPrint = layout;
break;
return false;
}

for ( QgsLayoutItem *item : items )
{
if ( item->type() == QgsLayoutItemRegistry::LayoutLabel && item->id() == QStringLiteral( "Title" ) )
{
QgsLayoutItemLabel *labelItem = qobject_cast<QgsLayoutItemLabel *>( item );
labelItem->setText( tr( "Map printed on %1 using QField" ).arg( "[%format_date(now(), 'yyyy-MM-dd @ hh:mm')%]" ) );
}
}
layoutToPrint = templateLayout.get();
}
else
{
for ( QgsPrintLayout *layout : printLayouts )
{
if ( layout->name() == layoutName || layoutName.isEmpty() )
{
layoutToPrint = layout;
break;
}
}
}

Expand Down Expand Up @@ -1324,7 +1354,7 @@ bool QgisMobileapp::printAtlasFeatures( const QString &layoutName, const QList<l
const QString priorFilterExpression = layoutToPrint->atlas()->filterExpression();
const bool priorFilterFeatures = layoutToPrint->atlas()->filterFeatures();

layoutToPrint->atlas()->setFilterExpression( QStringLiteral( "$id IN (%1)" ).arg( ids.join( ',' ) ), error );
layoutToPrint->atlas()->setFilterExpression( QStringLiteral( "@id IN (%1)" ).arg( ids.join( ',' ) ), error );
layoutToPrint->atlas()->setFilterFeatures( true );
layoutToPrint->atlas()->updateFeatures();

Expand Down
13 changes: 4 additions & 9 deletions src/qml/qgismobileapp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2488,16 +2488,11 @@ ApplicationWindow {
onShowPrintLayouts: p => {
if (layoutListInstantiator.count > 1) {
printMenu.popup(p.x, p.y);
} else if (layoutListInstantiator.count === 1) {
} else {
mainMenu.close();
displayToast(qsTr('Printing...'));
printMenu.printName = layoutListInstantiator.model.titleAt(0);
printMenu.printName = layoutListInstantiator.count === 1 ? layoutListInstantiator.model.titleAt(0) : "";
printMenu.printTimer.restart();
} else {
mainMenu.close();
toast.show(qsTr('No print layout available'), 'info', qsTr('Learn more'), function () {
Qt.openUrlExternally('https://docs.qfield.org/how-to/print-to-pdf/');
});
}
}

Expand Down Expand Up @@ -3113,7 +3108,7 @@ ApplicationWindow {
height: 48

onTriggered: {
featureForm.model.setFeatures(menu.featureLayer, '$id = ' + menu.fid);
featureForm.model.setFeatures(menu.featureLayer, '@id = ' + menu.fid);
featureForm.selection.focusedItem = 0;
featureForm.state = "FeatureForm";
}
Expand All @@ -3140,7 +3135,7 @@ ApplicationWindow {
height: 48

onTriggered: {
featureForm.model.setFeatures(menu.featureLayer, '$id = ' + menu.fid);
featureForm.model.setFeatures(menu.featureLayer, '@id = ' + menu.fid);
featureForm.selection.focusedItem = 0;
featureForm.multiSelection = true;
featureForm.selection.toggleSelectedItem(0);
Expand Down
Loading