Skip to content

Commit 30d4d6d

Browse files
MidnightCoder-mnirvn
authored andcommitted
Move QgisMobileapp into src/app behind an AppController interface
1 parent ae66671 commit 30d4d6d

8 files changed

Lines changed: 136 additions & 61 deletions

File tree

src/app/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ find_package(
6262
COMPONENTS Core5Compat
6363
REQUIRED)
6464

65+
set(QFIELD_APP_SRCS qgismobileapp.cpp)
66+
set(QFIELD_APP_HDRS qgismobileapp.h)
67+
68+
add_library(qfield_app STATIC ${QFIELD_APP_SRCS} ${QFIELD_APP_HDRS})
69+
70+
include(GenerateExportHeader)
71+
generate_export_header(qfield_app)
72+
73+
target_include_directories(qfield_app SYSTEM PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
74+
75+
target_include_directories(qfield_app PUBLIC ${CMAKE_SOURCE_DIR}/src/app)
76+
77+
target_compile_features(qfield_app PUBLIC cxx_std_20)
78+
79+
set_target_properties(qfield_app PROPERTIES AUTOMOC TRUE)
80+
81+
target_link_libraries(qfield_app PUBLIC qfield_core)
82+
6583
function(create_executable)
6684
cmake_parse_arguments(exe "" "TARGET" "EXTRA_ARGS" "" ${ARGN})
6785

@@ -100,7 +118,7 @@ function(create_executable)
100118
FILES
101119
${QM_FILES})
102120

103-
target_link_libraries(${exe_TARGET} PRIVATE qfield_core qfield_qml)
121+
target_link_libraries(${exe_TARGET} PRIVATE qfield_app qfield_core qfield_qml)
104122

105123
if(ANDROID)
106124
target_link_libraries(${exe_TARGET} PRIVATE qfield_service)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225

226226
QgisMobileapp::QgisMobileapp( QgsApplication *app, QObject *parent )
227227
: QQmlApplicationEngine( parent )
228-
, mIface( new AppInterface( this ) )
228+
, mIface( new AppInterface( this, this ) )
229229
, mFirstRenderingFlag( true )
230230
, mApp( app )
231231
{
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@
2929
#include <qgsunittypes.h>
3030

3131
// QField includes
32+
#include "appcontroller.h"
3233
#include "appcoordinateoperationhandlers.h"
3334
#include "bookmarkmodel.h"
3435
#include "clipboardmanager.h"
3536
#include "cogoregistry.h"
3637
#include "drawingtemplatemodel.h"
3738
#include "focusstack.h"
3839
#include "pluginmanager.h"
39-
#include "qfield_core_export.h"
40+
#include "qfield_app_export.h"
4041
#include "qfieldappauthrequesthandler.h"
4142
#include "qfieldurlhandler.h"
4243
#include "qgsgpkgflusher.h"
@@ -66,14 +67,14 @@ class QgsPrintLayout;
6667
#define REGISTER_SINGLETON( uri, _class, name ) qmlRegisterSingletonType<_class>( uri, 1, 0, name, []( QQmlEngine *engine, QJSEngine *scriptEngine ) -> QObject * { Q_UNUSED(engine); Q_UNUSED(scriptEngine); return new _class(); } )
6768

6869
/**
69-
* \defgroup core
70-
* \brief QField C++ classes
70+
* \defgroup app
71+
* \brief QField application C++ classes
7172
*/
7273

7374
/**
74-
* \ingroup core
75+
* \ingroup app
7576
*/
76-
class QFIELD_CORE_EXPORT QgisMobileapp : public QQmlApplicationEngine
77+
class QFIELD_APP_EXPORT QgisMobileapp : public QQmlApplicationEngine, public AppController
7778
{
7879
Q_OBJECT
7980
public:
@@ -87,20 +88,20 @@ class QFIELD_CORE_EXPORT QgisMobileapp : public QQmlApplicationEngine
8788
* \param name The project name
8889
* \note The actual loading is done in readProjectFile
8990
*/
90-
bool loadProjectFile( const QString &path, const QString &name = QString() );
91+
bool loadProjectFile( const QString &path, const QString &name = QString() ) override;
9192

9293
/**
9394
* Reloads the current project
9495
*
9596
* \note It does not reset the Auth Request Handler.
9697
* \note The actual loading is done in readProjectFile
9798
*/
98-
void reloadProjectFile();
99+
void reloadProjectFile() override;
99100

100101
/**
101102
* Reads and opens the project file set in the loadProjectFile function
102103
*/
103-
void readProjectFile();
104+
void readProjectFile() override;
104105

105106
/**
106107
* Reads a string from the specified \a scope and \a key from the currently opened project
@@ -111,7 +112,7 @@ class QFIELD_CORE_EXPORT QgisMobileapp : public QQmlApplicationEngine
111112
*
112113
* \returns entry value as string from \a scope given its \a key
113114
*/
114-
QString readProjectEntry( const QString &scope, const QString &key, const QString &def = QString() ) const;
115+
QString readProjectEntry( const QString &scope, const QString &key, const QString &def = QString() ) const override;
115116

116117
/**
117118
* Reads an integer from the specified \a scope and \a key from the currently opened project
@@ -122,7 +123,7 @@ class QFIELD_CORE_EXPORT QgisMobileapp : public QQmlApplicationEngine
122123
*
123124
* \returns entry value as integer from \a scope given its \a key
124125
*/
125-
int readProjectNumEntry( const QString &scope, const QString &key, int def = 0 ) const;
126+
int readProjectNumEntry( const QString &scope, const QString &key, int def = 0 ) const override;
126127

127128
/**
128129
* Reads a double from the specified \a scope and \a key from the currently opened project
@@ -133,7 +134,7 @@ class QFIELD_CORE_EXPORT QgisMobileapp : public QQmlApplicationEngine
133134
*
134135
* \returns entry value as double from \a scope given its \a key
135136
*/
136-
double readProjectDoubleEntry( const QString &scope, const QString &key, double def = 0.0 ) const;
137+
double readProjectDoubleEntry( const QString &scope, const QString &key, double def = 0.0 ) const override;
137138

138139
/**
139140
* Reads a boolean from the specified \a scope and \a key from the currently opened project
@@ -144,35 +145,35 @@ class QFIELD_CORE_EXPORT QgisMobileapp : public QQmlApplicationEngine
144145
*
145146
* \returns entry value as boolean from \a scope given its \a key
146147
*/
147-
bool readProjectBoolEntry( const QString &scope, const QString &key, bool def = false ) const;
148+
bool readProjectBoolEntry( const QString &scope, const QString &key, bool def = false ) const override;
148149

149150
/**
150151
* Prints a given layout from the currently opened project to a PDF file
151152
* \param layoutName the layout name that will be printed
152153
* \return TRUE if the layout was successfully printed
153154
*/
154-
bool print( const QString &layoutName );
155+
bool print( const QString &layoutName ) override;
155156

156157
/**
157158
* Prints a given atlas-driven layout from the currently opened project to one or more PDF files
158159
* \param layoutName the layout name that will be printed
159160
* \param featureIds the features from the atlas coverage vector layer that will be used to print the layout
160161
* \return TRUE if the layout was successfully printed
161162
*/
162-
bool printAtlasFeatures( const QString &layoutName, const QList<long long> &featureIds );
163+
bool printAtlasFeatures( const QString &layoutName, const QList<long long> &featureIds ) override;
163164

164165
/**
165166
* Sets the screen dimmer timeout in seconds
166167
* \note setting the timeout value to 0 will disable the screen dimmer
167168
*/
168-
void setScreenDimmerTimeout( int timeoutSeconds );
169+
void setScreenDimmerTimeout( int timeoutSeconds ) override;
169170

170171
bool event( QEvent *event ) override;
171172

172173
/**
173174
* Clear the currently opened project back to a blank project
174175
*/
175-
void clearProject();
176+
void clearProject() override;
176177

177178
static void initDeclarative( QQmlEngine *engine );
178179

src/core/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ set(QFIELD_CORE_SRCS
130130
qfieldappauthrequesthandler.cpp
131131
qfieldurlhandler.cpp
132132
qfieldxmlhttprequest.cpp
133-
qgismobileapp.cpp
134133
qgsgeometrywrapper.cpp
135134
qgsgpkgflusher.cpp
136135
recentprojectlistmodel.cpp
@@ -223,6 +222,7 @@ set(QFIELD_CORE_HDRS
223222
qfieldcloud/qfieldcloudproject.h
224223
qfieldcloud/qfieldcloudprojectsmodel.h
225224
qfieldcloud/qfieldcloudstatus.h
225+
appcontroller.h
226226
appcoordinateoperationhandlers.h
227227
appexpressioncontextscopesgenerator.h
228228
appinterface.h
@@ -285,7 +285,6 @@ set(QFIELD_CORE_HDRS
285285
qfieldappauthrequesthandler.h
286286
qfieldurlhandler.h
287287
qfieldxmlhttprequest.h
288-
qgismobileapp.h
289288
qgsgeometrywrapper.h
290289
qgsgpkgflusher.h
291290
recentprojectlistmodel.h

src/core/appcontroller.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/***************************************************************************
2+
appcontroller.h - AppController
3+
4+
---------------------
5+
begin : 19.7.2026
6+
copyright : (C) 2026 by Mohsen Dehghanzadeh
7+
email : info@opengis.ch
8+
***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#ifndef APPCONTROLLER_H
18+
#define APPCONTROLLER_H
19+
20+
#include <QList>
21+
#include <QString>
22+
23+
/**
24+
* \defgroup core
25+
* \brief QField C++ classes
26+
*/
27+
28+
/**
29+
* \brief Application operations that AppInterface delegates to the app.
30+
*
31+
* \ingroup core
32+
*/
33+
class AppController
34+
{
35+
public:
36+
virtual ~AppController() = default;
37+
38+
//! Loads a project file (.qgs/.qgz) or standalone dataset from \a path, labelled \a name.
39+
virtual bool loadProjectFile( const QString &path, const QString &name = QString() ) = 0;
40+
41+
//! Reloads the currently opened project.
42+
virtual void reloadProjectFile() = 0;
43+
44+
//! Reads the content of the loaded project.
45+
virtual void readProjectFile() = 0;
46+
47+
//! Reads a string project entry at \a scope / \a key (\a def if absent).
48+
virtual QString readProjectEntry( const QString &scope, const QString &key, const QString &def = QString() ) const = 0;
49+
50+
//! Reads an int project entry at \a scope / \a key (\a def if absent).
51+
virtual int readProjectNumEntry( const QString &scope, const QString &key, int def = 0 ) const = 0;
52+
53+
//! Reads a double project entry at \a scope / \a key (\a def if absent).
54+
virtual double readProjectDoubleEntry( const QString &scope, const QString &key, double def = 0.0 ) const = 0;
55+
56+
//! Reads a bool project entry at \a scope / \a key (\a def if absent).
57+
virtual bool readProjectBoolEntry( const QString &scope, const QString &key, bool def = false ) const = 0;
58+
59+
//! Prints the project layout matching \a layoutName to PDF.
60+
virtual bool print( const QString &layoutName ) = 0;
61+
62+
//! Prints the atlas-driven layout \a layoutName for \a featureIds to PDF.
63+
virtual bool printAtlasFeatures( const QString &layoutName, const QList<long long> &featureIds ) = 0;
64+
65+
//! Sets the screen dimmer timeout in seconds (0 disables dimming).
66+
virtual void setScreenDimmerTimeout( int timeoutSeconds ) = 0;
67+
68+
//! Clears the currently opened project.
69+
virtual void clearProject() = 0;
70+
};
71+
72+
#endif // APPCONTROLLER_H

0 commit comments

Comments
 (0)