QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsprocessingmodelcomponent.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsprocessingmodelcomponent.cpp
3 -------------------------------
4 begin : June 2017
5 copyright : (C) 2017 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
19
20#include "qgscolorutils.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
28
29QgsProcessingModelComponent::QgsProcessingModelComponent( const QString &description )
30 : mDescription( description )
31{}
32
33QString QgsProcessingModelComponent::description() const
34{
35 return mDescription;
36}
37
38void QgsProcessingModelComponent::setDescription( const QString &description )
39{
40 mDescription = description;
41}
42
43QPointF QgsProcessingModelComponent::position() const
44{
45 return mPosition;
46}
47
48void QgsProcessingModelComponent::setPosition( QPointF position )
49{
50 mPosition = position;
51}
52
53QSizeF QgsProcessingModelComponent::size() const
54{
55 return mSize;
56}
57
58void QgsProcessingModelComponent::setSize( QSizeF size )
59{
60 mSize = size;
61}
62
63QColor QgsProcessingModelComponent::color() const
64{
65 return mColor;
66}
67
68void QgsProcessingModelComponent::setColor( const QColor &color )
69{
70 mColor = color;
71}
72
73bool QgsProcessingModelComponent::linksCollapsed( Qt::Edge edge ) const
74{
75 switch ( edge )
76 {
77 case Qt::TopEdge:
78 return mTopEdgeLinksCollapsed;
79
80 case Qt::BottomEdge:
81 return mBottomEdgeLinksCollapsed;
82
83 case Qt::LeftEdge:
84 case Qt::RightEdge:
85 return false;
86 }
87 return false;
88}
89
90void QgsProcessingModelComponent::setLinksCollapsed( Qt::Edge edge, bool collapsed )
91{
92 switch ( edge )
93 {
94 case Qt::TopEdge:
95 mTopEdgeLinksCollapsed = collapsed;
96 break;
97
98 case Qt::BottomEdge:
99 mBottomEdgeLinksCollapsed = collapsed;
100 break;
101
102 case Qt::LeftEdge:
103 case Qt::RightEdge:
104 break;
105 }
106}
107
108void QgsProcessingModelComponent::setComment( const QgsProcessingModelComment & )
109{
110
111}
112
113void QgsProcessingModelComponent::saveCommonProperties( QVariantMap &map ) const
114{
115 map.insert( u"component_pos_x"_s, mPosition.x() );
116 map.insert( u"component_pos_y"_s, mPosition.y() );
117 map.insert( u"component_description"_s, mDescription );
118 map.insert( u"component_width"_s, mSize.width() );
119 map.insert( u"component_height"_s, mSize.height() );
120 map.insert( u"parameters_collapsed"_s, mTopEdgeLinksCollapsed );
121 map.insert( u"outputs_collapsed"_s, mBottomEdgeLinksCollapsed );
122 map.insert( u"color"_s, mColor.isValid() ? QgsColorUtils::colorToString( mColor ) : QString() );
123 const QgsProcessingModelComment *thisComment = comment();
124 if ( thisComment )
125 map.insert( u"comment"_s, thisComment->toVariant() );
126}
127
128void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &map )
129{
130 QPointF pos;
131 pos.setX( map.value( u"component_pos_x"_s ).toDouble() );
132 pos.setY( map.value( u"component_pos_y"_s ).toDouble() );
133 mPosition = pos;
134 mDescription = map.value( u"component_description"_s ).toString();
135 mSize.setWidth( map.value( u"component_width"_s, QString::number( DEFAULT_COMPONENT_WIDTH ) ).toDouble() );
136 mSize.setHeight( map.value( u"component_height"_s, QString::number( DEFAULT_COMPONENT_HEIGHT ) ).toDouble() );
137 mColor = map.value( u"color"_s ).toString().isEmpty() ? QColor() : QgsColorUtils::colorFromString( map.value( u"color"_s ).toString() );
138 mTopEdgeLinksCollapsed = map.value( u"parameters_collapsed"_s ).toBool();
139 mBottomEdgeLinksCollapsed = map.value( u"outputs_collapsed"_s ).toBool();
140 QgsProcessingModelComment *thisComment = comment();
141 if ( thisComment )
142 thisComment->loadVariant( map.value( u"comment"_s ).toMap() );
143}
144
145void QgsProcessingModelComponent::copyNonDefinitionProperties( const QgsProcessingModelComponent &other )
146{
147 setPosition( other.position() );
148 setSize( other.size() );
149 setLinksCollapsed( Qt::TopEdge, other.linksCollapsed( Qt::TopEdge ) );
150 setLinksCollapsed( Qt::BottomEdge, other.linksCollapsed( Qt::BottomEdge ) );
151 QgsProcessingModelComment *thisComment = comment();
152 const QgsProcessingModelComment *otherComment = other.comment();
153 if ( thisComment && otherComment )
154 {
155 if ( !otherComment->position().isNull() )
156 thisComment->setPosition( otherComment->position() );
157 else
158 thisComment->setPosition( other.position() + QPointF( size().width(), -1.5 * size().height() ) );
159 thisComment->setSize( otherComment->size() );
160 }
161}
162
Contains utility functions for working with colors.
static QString colorToString(const QColor &color)
Encodes a color into a string value.