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