1 /*************************************************************************** 2 qgsprojectservervalidator.h 3 --------------------------- 4 begin : March 2020 5 copyright : (C) 2020 by Etienne Trimaille 6 email : etienne dot trimaille at gmail dot com 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef QGSPROJECTSERVERVALIDATOR_H 19 #define QGSPROJECTSERVERVALIDATOR_H 20 21 #include "qgis_core.h" 22 #include "qgis_sip.h" 23 #include "qgslayertreegroup.h" 24 #include "qgslayertree.h" 25 26 27 /** 28 * \ingroup core 29 * \class QgsProjectServerValidator 30 * \brief Validates the server specific parts of the configuration of a QGIS project. 31 * \since QGIS 3.14 32 */ 33 class CORE_EXPORT QgsProjectServerValidator 34 { 35 36 public: 37 38 /** 39 * Constructor for QgsProjectServerValidator. 40 */ 41 QgsProjectServerValidator() = default; 42 43 /** 44 * Errors that might be raised by the validation process. 45 */ 46 enum ValidationError 47 { 48 DuplicatedNames = 0, //!< A duplicated layer/group name in the layer tree. 49 LayerShortName = 1, //!< Layer/group short name is not valid. 50 LayerEncoding = 2, //!< Encoding is not correctly set on a vector layer. 51 ProjectShortName = 3, //!< The project short name is not valid. 52 ProjectRootNameConflict = 4, //!< The project root name is already used by a layer or a group. 53 }; 54 55 /** 56 * Returns a human readable string for a given error. 57 * \param error the error. 58 * \returns the human readable error. 59 */ 60 static QString displayValidationError( QgsProjectServerValidator::ValidationError error ); 61 62 /** 63 * Contains the parameters describing a project validation failure. 64 */ 65 struct ValidationResult 66 { 67 68 /** 69 * Constructor for ValidationResult. 70 */ ValidationResultValidationResult71 ValidationResult( const QgsProjectServerValidator::ValidationError error, const QVariant &identifier ) 72 : error( error ) 73 , identifier( identifier ) 74 {} 75 76 /** 77 * Error which occurred during the validation process. 78 */ 79 QgsProjectServerValidator::ValidationError error; 80 81 /** 82 * Identifier related to the error. It can be a layer/group name. 83 */ 84 QVariant identifier; 85 }; 86 87 /** 88 * Validates a project to detect problems on QGIS Server, and returns TRUE if it's considered valid. 89 * If validation fails, the \a results list will be filled with a list of 90 * items describing why the validation failed and what needs to be rectified 91 * \param project input project to check 92 * \param results results of the validation 93 * \returns bool 94 */ 95 static bool validate( QgsProject *project, QList< QgsProjectServerValidator::ValidationResult > &results SIP_OUT ); 96 97 private: 98 static void browseLayerTree( QgsLayerTreeGroup *treeGroup, QStringList &owsNames, QStringList &encodingMessages ); 99 100 }; 101 102 #endif // QGSPROJECTSERVERVALIDATOR_H 103