LCOV - code coverage report
Current view: top level - analysis/processing - qgsalgorithmcreatedirectory.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 41 0.0 %
Date: 2021-03-26 12:19:53 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /***************************************************************************
       2                 :            :                          qgsalgorithmcreatedirectory.cpp
       3                 :            :                          ---------------------
       4                 :            :     begin                : June 2020
       5                 :            :     copyright            : (C) 2020 by Nyall Dawson
       6                 :            :     email                : nyall dot dawson 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                 :            : #include "qgsalgorithmcreatedirectory.h"
      18                 :            : 
      19                 :            : ///@cond PRIVATE
      20                 :            : 
      21                 :          0 : QString QgsCreateDirectoryAlgorithm::name() const
      22                 :            : {
      23                 :          0 :   return QStringLiteral( "createdirectory" );
      24                 :            : }
      25                 :            : 
      26                 :          0 : QgsProcessingAlgorithm::Flags QgsCreateDirectoryAlgorithm::flags() const
      27                 :            : {
      28                 :          0 :   return FlagHideFromToolbox | FlagSkipGenericModelLogging;
      29                 :            : }
      30                 :            : 
      31                 :          0 : QString QgsCreateDirectoryAlgorithm::displayName() const
      32                 :            : {
      33                 :          0 :   return QObject::tr( "Create directory" );
      34                 :            : }
      35                 :            : 
      36                 :          0 : QStringList QgsCreateDirectoryAlgorithm::tags() const
      37                 :            : {
      38                 :          0 :   return QObject::tr( "new,make,folder" ).split( ',' );
      39                 :          0 : }
      40                 :            : 
      41                 :          0 : QString QgsCreateDirectoryAlgorithm::group() const
      42                 :            : {
      43                 :          0 :   return QObject::tr( "File tools" );
      44                 :            : }
      45                 :            : 
      46                 :          0 : QString QgsCreateDirectoryAlgorithm::groupId() const
      47                 :            : {
      48                 :          0 :   return QStringLiteral( "filetools" );
      49                 :            : }
      50                 :            : 
      51                 :          0 : QString QgsCreateDirectoryAlgorithm::shortHelpString() const
      52                 :            : {
      53                 :          0 :   return QObject::tr( "This algorithm creates a new directory on a file system. Directories will be created recursively, creating all "
      54                 :            :                       "required parent directories in order to construct the full specified directory path.\n\n"
      55                 :            :                       "No errors will be raised if the directory already exists." );
      56                 :            : }
      57                 :            : 
      58                 :          0 : QString QgsCreateDirectoryAlgorithm::shortDescription() const
      59                 :            : {
      60                 :          0 :   return QObject::tr( "Creates a new directory on a file system." );
      61                 :            : }
      62                 :            : 
      63                 :          0 : QgsCreateDirectoryAlgorithm *QgsCreateDirectoryAlgorithm::createInstance() const
      64                 :            : {
      65                 :          0 :   return new QgsCreateDirectoryAlgorithm();
      66                 :            : }
      67                 :            : 
      68                 :          0 : void QgsCreateDirectoryAlgorithm::initAlgorithm( const QVariantMap & )
      69                 :            : {
      70                 :          0 :   addParameter( new QgsProcessingParameterMapLayer( QStringLiteral( "PATH" ), QObject::tr( "Directory path" ) ) );
      71                 :          0 :   addOutput( new QgsProcessingOutputFolder( QStringLiteral( "OUTPUT" ), QObject::tr( "Directory" ) ) );
      72                 :          0 : }
      73                 :            : 
      74                 :          0 : QVariantMap QgsCreateDirectoryAlgorithm::processAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
      75                 :            : {
      76                 :          0 :   const QString path = parameterAsString( parameters, QStringLiteral( "PATH" ), context );
      77                 :            : 
      78                 :          0 :   if ( !path.isEmpty() )
      79                 :            :   {
      80                 :          0 :     if ( QFile::exists( path ) )
      81                 :            :     {
      82                 :          0 :       if ( !QFileInfo( path ).isDir() )
      83                 :          0 :         throw QgsProcessingException( QObject::tr( "A file with the name %1 already exists -- cannot create a new directory here." ).arg( path ) );
      84                 :          0 :       if ( feedback )
      85                 :          0 :         feedback->pushInfo( QObject::tr( "The directory %1 already exists." ).arg( path ) );
      86                 :          0 :     }
      87                 :            :     else
      88                 :            :     {
      89                 :          0 :       if ( !QDir().mkpath( path ) )
      90                 :            :       {
      91                 :          0 :         throw QgsProcessingException( QObject::tr( "Could not create directory %1. Please check that you have write permissions for the specified path." ).arg( path ) );
      92                 :            :       }
      93                 :            : 
      94                 :          0 :       if ( feedback )
      95                 :          0 :         feedback->pushInfo( QObject::tr( "Created %1" ).arg( path ) );
      96                 :            :     }
      97                 :          0 :   }
      98                 :            : 
      99                 :          0 :   QVariantMap results;
     100                 :          0 :   results.insert( QStringLiteral( "OUTPUT" ), path );
     101                 :          0 :   return results;
     102                 :          0 : }
     103                 :            : 
     104                 :            : ///@endcond

Generated by: LCOV version 1.14