mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-04 00:04:03 -04:00
adding model designer style customization
This commit is contained in:
parent
5c8d471789
commit
99613254d1
@ -224,8 +224,21 @@ QString QgsProcessingModelChildParameterSource::friendlyIdentifier( QgsProcessin
|
||||
switch ( mSource )
|
||||
{
|
||||
case Qgis::ProcessingModelChildParameterSource::ModelParameter:
|
||||
return model ? model->parameterDefinition( mParameterName )->description() : mParameterName;
|
||||
{
|
||||
if (model) {
|
||||
const QgsProcessingParameterDefinition* paramDefinition = model->parameterDefinition( mParameterName );
|
||||
|
||||
// A model can be valid (non null) but we could be looking for a null parameter (if input if not set yet)
|
||||
if (paramDefinition == nullptr) {
|
||||
return mParameterName;
|
||||
} else {
|
||||
return model->parameterDefinition( mParameterName )->description();
|
||||
}
|
||||
|
||||
} else {
|
||||
return mParameterName;
|
||||
}
|
||||
}
|
||||
case Qgis::ProcessingModelChildParameterSource::ChildOutput:
|
||||
{
|
||||
if ( model )
|
||||
|
@ -230,6 +230,11 @@ class CORE_EXPORT QgsProcessingModelChildParameterSource
|
||||
*/
|
||||
QString friendlyIdentifier( QgsProcessingModelAlgorithm *model ) const;
|
||||
|
||||
/**
|
||||
* Returns the type of source
|
||||
*/
|
||||
Qgis::ProcessingModelChildParameterSource getSourceType() { return mSource; }
|
||||
|
||||
private:
|
||||
|
||||
Qgis::ProcessingModelChildParameterSource mSource = Qgis::ProcessingModelChildParameterSource::StaticValue;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsmodelgraphicsscene.h"
|
||||
#include "qgsmodelcomponentgraphicitem.h"
|
||||
#include "qgsmodelgraphicitem.h"
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QPalette>
|
||||
@ -72,7 +73,19 @@ QgsModelArrowItem::QgsModelArrowItem( QgsModelComponentGraphicItem *startItem, M
|
||||
|
||||
void QgsModelArrowItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * )
|
||||
{
|
||||
QColor color = mColor;
|
||||
QString dataType;
|
||||
|
||||
// Possibly, the mComponentItem is an instance of QgsModelParameterGraphicItem. In this case,
|
||||
// it needs to be explicitely casted so that the relevant getLinkedParamDataType method is being called
|
||||
if (QgsModelParameterGraphicItem *paramItem = dynamic_cast<QgsModelParameterGraphicItem *>(mStartItem)){
|
||||
dataType = paramItem->getLinkedParamDataType(mStartEdge, mStartIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataType = mStartItem->getLinkedParamDataType(mStartEdge, mStartIndex);
|
||||
}
|
||||
|
||||
QColor color = QgsModelDesignerSocketGraphicItem::typeToColorLookup(dataType);
|
||||
|
||||
if ( mStartItem->state() == QgsModelComponentGraphicItem::Selected || mEndItem->state() == QgsModelComponentGraphicItem::Selected )
|
||||
color.setAlpha( 220 );
|
||||
@ -83,12 +96,11 @@ void QgsModelArrowItem::paint( QPainter *painter, const QStyleOptionGraphicsItem
|
||||
|
||||
QPen p = pen();
|
||||
p.setColor( color );
|
||||
p.setWidth( 1 );
|
||||
p.setWidth( 2 );
|
||||
painter->setPen( p );
|
||||
painter->setBrush( color );
|
||||
painter->setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
|
||||
switch ( mStartMarker )
|
||||
{
|
||||
case Marker::Circle:
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "qgsmodelviewmouseevent.h"
|
||||
#include "qgsmodelgroupboxdefinitionwidget.h"
|
||||
#include "qgsmessagelog.h"
|
||||
#include "qgsprocessingparameters.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QPicture>
|
||||
@ -498,35 +499,51 @@ QPixmap QgsModelComponentGraphicItem::iconPixmap() const
|
||||
|
||||
void QgsModelComponentGraphicItem::updateButtonPositions()
|
||||
{
|
||||
bool isParameter = dynamic_cast<QgsProcessingModelParameter *>(mComponent.get()) != nullptr;
|
||||
mEditButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - BUTTON_MARGIN, itemSize().height() / 2.0 - mButtonSize.height() / 2.0 - BUTTON_MARGIN ) );
|
||||
mDeleteButton->setPosition( QPointF( itemSize().width() / 2.0 - mButtonSize.width() / 2.0 - BUTTON_MARGIN, mButtonSize.height() / 2.0 - itemSize().height() / 2.0 + BUTTON_MARGIN ) );
|
||||
|
||||
if ( mExpandTopButton )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::TopEdge, -1, true );
|
||||
mExpandTopButton->setPosition( QPointF( 0, pt.y() ) );
|
||||
}
|
||||
if ( mExpandBottomButton )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::BottomEdge, -1, false );
|
||||
mExpandBottomButton->setPosition( QPointF( 0, pt.y() ) );
|
||||
}
|
||||
if (isParameter) {
|
||||
if ( mExpandBottomButton )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::BottomEdge, -1, false );
|
||||
mExpandBottomButton->setPosition( QPointF( 0, pt.y() ) );
|
||||
}
|
||||
|
||||
bool collapsed = mComponent->linksCollapsed( Qt::BottomEdge );
|
||||
for ( QgsModelDesignerSocketGraphicItem *socket : std::as_const( mOutSockets ) )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::BottomEdge, socket->index(), false );
|
||||
socket->setPosition( pt );
|
||||
socket->setVisible( !collapsed );
|
||||
}
|
||||
} else {
|
||||
if ( mExpandTopButton )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::TopEdge, -1, true );
|
||||
mExpandTopButton->setPosition( QPointF( 0, pt.y() ) );
|
||||
}
|
||||
if ( mExpandBottomButton )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::BottomEdge, -1, false );
|
||||
mExpandBottomButton->setPosition( QPointF( 0, pt.y() ) );
|
||||
}
|
||||
|
||||
bool collapsed = mComponent->linksCollapsed( Qt::TopEdge );
|
||||
for ( QgsModelDesignerSocketGraphicItem *socket : std::as_const( mInSockets ) )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::TopEdge, socket->index(), true );
|
||||
socket->setPosition( pt );
|
||||
socket->setVisible( !collapsed );
|
||||
}
|
||||
bool collapsed = mComponent->linksCollapsed( Qt::TopEdge );
|
||||
for ( QgsModelDesignerSocketGraphicItem *socket : std::as_const( mInSockets ) )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::TopEdge, socket->index(), true );
|
||||
socket->setPosition( pt );
|
||||
socket->setVisible( !collapsed );
|
||||
}
|
||||
|
||||
collapsed = mComponent->linksCollapsed( Qt::BottomEdge );
|
||||
for ( QgsModelDesignerSocketGraphicItem *socket : std::as_const( mOutSockets ) )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::BottomEdge, socket->index(), false );
|
||||
socket->setPosition( pt );
|
||||
socket->setVisible( !collapsed );
|
||||
collapsed = mComponent->linksCollapsed( Qt::BottomEdge );
|
||||
for ( QgsModelDesignerSocketGraphicItem *socket : std::as_const( mOutSockets ) )
|
||||
{
|
||||
const QPointF pt = linkPoint( Qt::BottomEdge, socket->index(), false );
|
||||
socket->setPosition( pt );
|
||||
socket->setVisible( !collapsed );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,16 +579,17 @@ void QgsModelComponentGraphicItem::fold( Qt::Edge edge, bool folded )
|
||||
// also need to update the model's stored component
|
||||
|
||||
// TODO - this is not so nice, consider moving this to model class
|
||||
if ( QgsProcessingModelChildAlgorithm *child = dynamic_cast<QgsProcessingModelChildAlgorithm *>( mComponent.get() ) )
|
||||
if ( QgsProcessingModelChildAlgorithm *child = dynamic_cast<QgsProcessingModelChildAlgorithm *>( mComponent.get() ) ){
|
||||
mModel->childAlgorithm( child->childId() ).setLinksCollapsed( edge, folded );
|
||||
else if ( QgsProcessingModelParameter *param = dynamic_cast<QgsProcessingModelParameter *>( mComponent.get() ) )
|
||||
mModel->parameterComponent( param->parameterName() ).setLinksCollapsed( edge, folded );
|
||||
else if ( QgsProcessingModelOutput *output = dynamic_cast<QgsProcessingModelOutput *>( mComponent.get() ) )
|
||||
} else if ( QgsProcessingModelParameter *param = dynamic_cast<QgsProcessingModelParameter *>( mComponent.get() ) ) {
|
||||
QString paramName = param->parameterName();
|
||||
QgsProcessingModelParameter paramComp = mModel->parameterComponent( paramName );
|
||||
paramComp.setLinksCollapsed( edge, folded );
|
||||
} else if ( QgsProcessingModelOutput *output = dynamic_cast<QgsProcessingModelOutput *>( mComponent.get() ) ){
|
||||
mModel->childAlgorithm( output->childId() ).modelOutput( output->name() ).setLinksCollapsed( edge, folded );
|
||||
|
||||
}
|
||||
|
||||
updateButtonPositions();
|
||||
|
||||
prepareGeometryChange();
|
||||
emit updateArrowPaths();
|
||||
emit changed();
|
||||
@ -627,8 +645,8 @@ QPointF QgsModelComponentGraphicItem::linkPoint( Qt::Edge edge, int index, bool
|
||||
const QFontMetricsF fm( mFont );
|
||||
const double w = fm.boundingRect( text ).width();
|
||||
const double h = fm.height() * 1.2 * ( pointIndex + 1 ) + fm.height() / 2.0;
|
||||
const double y = h + itemSize().height() / 2.0 + 5;
|
||||
const double x = !mComponent->linksCollapsed( Qt::BottomEdge ) ? ( -itemSize().width() / 2 + 33 + w + 5 ) : 10;
|
||||
const double y = h + itemSize().height() / 2.0 + 6;
|
||||
const double x = !mComponent->linksCollapsed( Qt::BottomEdge ) ? ( -itemSize().width() / 2 + 33 + w + 10 ) : 10;
|
||||
return QPointF( incoming ? -itemSize().width() / 2 + offsetX : x, y );
|
||||
}
|
||||
break;
|
||||
@ -842,6 +860,18 @@ QString QgsModelParameterGraphicItem::linkPointText( Qt::Edge, int index ) const
|
||||
if ( const QgsProcessingModelParameter *parameter = dynamic_cast< const QgsProcessingModelParameter * >( component() ) )
|
||||
{
|
||||
QString text = this->model()->parameterDefinition( parameter->parameterName() )->type();
|
||||
|
||||
// Getting the default value to append to the box name
|
||||
if (const QgsProcessingParameterDefinition *paramDef = this->model()->parameterDefinition(parameter->parameterName()))
|
||||
{
|
||||
QVariant paramValue = paramDef->defaultValue();
|
||||
|
||||
if (paramValue.isValid() && !paramValue.toString().isEmpty())
|
||||
{
|
||||
text += ": " + paramValue.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return truncatedTextForItem( text );
|
||||
}
|
||||
|
||||
@ -849,6 +879,26 @@ QString QgsModelParameterGraphicItem::linkPointText( Qt::Edge, int index ) const
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString QgsModelParameterGraphicItem::getLinkedParamDataType(Qt::Edge edge, int index)
|
||||
{
|
||||
QString unknownType = QString("unknown");
|
||||
|
||||
if ( index < 0 )
|
||||
{
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
if ( const QgsProcessingModelParameter *parameter = dynamic_cast< const QgsProcessingModelParameter * >( component() ) )
|
||||
{
|
||||
return this->model()->parameterDefinition( parameter->parameterName() )->type();
|
||||
}
|
||||
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
|
||||
void QgsModelParameterGraphicItem::updateStoredComponentPosition( const QPointF &pos, const QSizeF &size )
|
||||
{
|
||||
if ( QgsProcessingModelParameter *param = dynamic_cast<QgsProcessingModelParameter *>( component() ) )
|
||||
@ -1087,6 +1137,48 @@ int QgsModelChildAlgorithmGraphicItem::linkPointCount( Qt::Edge edge ) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
QString QgsModelComponentGraphicItem::getLinkedParamDataType(Qt::Edge edge, int index)
|
||||
{
|
||||
QString unknownType = QString("unknown");
|
||||
|
||||
if ( const QgsProcessingModelChildAlgorithm *child = dynamic_cast<const QgsProcessingModelChildAlgorithm *>( component() ) )
|
||||
{
|
||||
if ( !child->algorithm() ) {
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
switch ( edge )
|
||||
{
|
||||
case Qt::BottomEdge:
|
||||
{
|
||||
if (index <= child->algorithm()->outputDefinitions().size() - 1) {
|
||||
return child->algorithm()->outputDefinitions().at(index)->type();
|
||||
}
|
||||
return unknownType;
|
||||
}
|
||||
case Qt::TopEdge:
|
||||
{
|
||||
QgsProcessingParameterDefinitions params = child->algorithm()->parameterDefinitions();
|
||||
|
||||
if (index <= params.size() - 1) {
|
||||
return params.at(index)->type();
|
||||
}
|
||||
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
case Qt::LeftEdge:
|
||||
case Qt::RightEdge:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int index ) const
|
||||
{
|
||||
if ( index < 0 )
|
||||
@ -1099,6 +1191,7 @@ QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int ind
|
||||
|
||||
const QVariantMap inputs = mResults.inputs();
|
||||
const QVariantMap outputs = mResults.outputs();
|
||||
|
||||
switch ( edge )
|
||||
{
|
||||
case Qt::BottomEdge:
|
||||
@ -1115,10 +1208,6 @@ QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int ind
|
||||
|
||||
const QgsProcessingOutputDefinition *output = child->algorithm()->outputDefinitions().at( index );
|
||||
QString title = output->description();
|
||||
if ( outputs.contains( output->name() ) )
|
||||
{
|
||||
title += QStringLiteral( ": %1" ).arg( outputs.value( output->name() ).toString() );
|
||||
}
|
||||
return truncatedTextForItem( title );
|
||||
}
|
||||
|
||||
@ -1140,9 +1229,60 @@ QString QgsModelChildAlgorithmGraphicItem::linkPointText( Qt::Edge edge, int ind
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString title = params.at( index )->description();
|
||||
if ( !inputs.value( params.at( index )->name() ).toString().isEmpty() )
|
||||
title += QStringLiteral( ": %1" ).arg( inputs.value( params.at( index )->name() ).toString() );
|
||||
const QgsProcessingParameterDefinition* param = params.at( index );
|
||||
QString name = param->name();
|
||||
QString title = param->description();
|
||||
|
||||
|
||||
QgsProcessingModelChildParameterSources paramSources = child->parameterSources().value(name);
|
||||
QString paramValueAsStr = "";
|
||||
|
||||
if (paramSources.size() > 0) {
|
||||
QgsProcessingModelChildParameterSource firstParamSource = paramSources[0];
|
||||
|
||||
switch(firstParamSource.getSourceType()) {
|
||||
|
||||
case Qgis::ProcessingModelChildParameterSource::ChildOutput:
|
||||
paramValueAsStr = QStringLiteral( ": %1" ).arg(
|
||||
firstParamSource.friendlyIdentifier(const_cast<QgsProcessingModelAlgorithm *>(model()))
|
||||
);
|
||||
break;
|
||||
|
||||
case Qgis::ProcessingModelChildParameterSource::Expression:
|
||||
paramValueAsStr = QStringLiteral( ": %1" ).arg(firstParamSource.expression());
|
||||
break;
|
||||
|
||||
case Qgis::ProcessingModelChildParameterSource::ExpressionText:
|
||||
paramValueAsStr = QStringLiteral( ": %1" ).arg(firstParamSource.expressionText());
|
||||
break;
|
||||
|
||||
case Qgis::ProcessingModelChildParameterSource::ModelOutput:
|
||||
paramValueAsStr = QStringLiteral( ": output from '%1'" ).arg(
|
||||
firstParamSource.friendlyIdentifier(const_cast<QgsProcessingModelAlgorithm *>(model()))
|
||||
);
|
||||
break;
|
||||
|
||||
case Qgis::ProcessingModelChildParameterSource::ModelParameter:
|
||||
{
|
||||
QString friendlyName = firstParamSource.friendlyIdentifier(const_cast<QgsProcessingModelAlgorithm *>(model()));
|
||||
paramValueAsStr = friendlyName.isEmpty() ? QStringLiteral( ":" ) : QStringLiteral( ": value from '%1'" ).arg(friendlyName);
|
||||
break;
|
||||
}
|
||||
|
||||
case Qgis::ProcessingModelChildParameterSource::StaticValue:
|
||||
default:
|
||||
QVariant paramValue = paramSources[0].staticValue();
|
||||
paramValueAsStr = QStringLiteral( ": %1" ).arg(paramValue.toString());
|
||||
|
||||
// In case of an enum, we want to display the label of the enum value (and not just its index as an int)
|
||||
if (param->type() == QgsProcessingParameterEnum::typeName()) {
|
||||
const QgsProcessingParameterEnum* paramAsEnumParam = dynamic_cast<const QgsProcessingParameterEnum *>(param);
|
||||
paramValueAsStr = QStringLiteral( ": %1" ).arg(paramAsEnumParam->options().at(paramValue.toInt()));
|
||||
}
|
||||
}
|
||||
title += paramValueAsStr;
|
||||
}
|
||||
|
||||
return truncatedTextForItem( title );
|
||||
}
|
||||
|
||||
@ -1172,7 +1312,7 @@ bool QgsModelChildAlgorithmGraphicItem::canDeleteComponent()
|
||||
return false;
|
||||
}
|
||||
|
||||
void QgsModelChildAlgorithmGraphicItem::setResults( const QgsProcessingModelChildAlgorithmResult &results )
|
||||
void QgsModelChildAlgorithmGraphicItem::setResults( const QgsProcessingModelChildAlgorithmResult &results)
|
||||
{
|
||||
if ( mResults == results )
|
||||
return;
|
||||
|
@ -137,6 +137,8 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
|
||||
*/
|
||||
void setItemRect( QRectF rect );
|
||||
|
||||
QString getLinkedParamDataType(Qt::Edge edge, int index);
|
||||
|
||||
#ifndef SIP_RUN
|
||||
|
||||
/**
|
||||
@ -237,7 +239,7 @@ class GUI_EXPORT QgsModelComponentGraphicItem : public QGraphicsObject
|
||||
|
||||
/**
|
||||
* Returns the output socket graphics items at the specified \a index.
|
||||
*
|
||||
*
|
||||
* May return NULLPTR if no corresponding output socket exists.
|
||||
* \since QGIS 3.44
|
||||
*/
|
||||
@ -427,6 +429,8 @@ class GUI_EXPORT QgsModelParameterGraphicItem : public QgsModelComponentGraphicI
|
||||
void contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) override;
|
||||
bool canDeleteComponent() override;
|
||||
|
||||
QString getLinkedParamDataType( Qt::Edge edge, int index );
|
||||
|
||||
protected:
|
||||
QColor fillColor( State state ) const override;
|
||||
QColor strokeColor( State state ) const override;
|
||||
|
@ -21,6 +21,11 @@
|
||||
#include "qgsmodelgraphicsview.h"
|
||||
#include "qgsmodelviewtool.h"
|
||||
#include "qgsmodelviewmouseevent.h"
|
||||
#include "qgsprocessingmodelcomponent.h"
|
||||
#include "qgsprocessingoutputs.h"
|
||||
#include "qgsprocessingparameters.h"
|
||||
#include "qgsprocessingmodelchildalgorithm.h"
|
||||
#include "qgsprocessingalgorithm.h"
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QSvgRenderer>
|
||||
@ -180,12 +185,20 @@ QgsModelDesignerSocketGraphicItem::QgsModelDesignerSocketGraphicItem( QgsModelCo
|
||||
|
||||
void QgsModelDesignerSocketGraphicItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * )
|
||||
{
|
||||
painter->setPen( QPen() );
|
||||
painter->setBrush( QBrush( QColor( 0, 0, 0, mHoverState ? 200 : 33 ), Qt::SolidPattern ) );
|
||||
|
||||
QColor outlineColor = getColor();
|
||||
QColor fillColor = QColor(outlineColor);
|
||||
fillColor.setAlpha(isDefaultParamValue() ? 30 : 255);
|
||||
|
||||
// Outline style
|
||||
painter->setPen(QPen(outlineColor, mHoverState ? mSocketOutlineWidth * 2 : mSocketOutlineWidth));
|
||||
|
||||
// Fill style
|
||||
painter->setBrush( QBrush( fillColor, Qt::SolidPattern ) );
|
||||
|
||||
painter->setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
constexpr float DISPLAY_SIZE = 3.2;
|
||||
constexpr float DISPLAY_SIZE = 4;
|
||||
painter->drawEllipse( position(), DISPLAY_SIZE, DISPLAY_SIZE );
|
||||
/* Uncomment to display bounding box */
|
||||
#if 0
|
||||
@ -197,4 +210,204 @@ void QgsModelDesignerSocketGraphicItem::paint( QPainter *painter, const QStyleOp
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
QColor QgsModelDesignerSocketGraphicItem::getColor() {
|
||||
QString dataType;
|
||||
|
||||
// Possibly, the mComponentItem is an instance of QgsModelParameterGraphicItem. In this case,
|
||||
// it needs to be explicitely casted so that the relevant getLinkedParamDataType method is being called
|
||||
if (QgsModelParameterGraphicItem *paramItem = dynamic_cast<QgsModelParameterGraphicItem *>(componentItem()))
|
||||
{
|
||||
dataType = paramItem->getLinkedParamDataType(mEdge, mIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
dataType = componentItem()->getLinkedParamDataType(mEdge, mIndex);
|
||||
}
|
||||
|
||||
return QgsModelDesignerSocketGraphicItem::typeToColorLookup(dataType);
|
||||
|
||||
}
|
||||
|
||||
|
||||
QColor QgsModelDesignerSocketGraphicItem::typeToColorLookup(QString dataType) {
|
||||
|
||||
// Numerical types
|
||||
if(
|
||||
dataType == QgsProcessingParameterMatrix::typeName() ||
|
||||
dataType == QgsProcessingParameterNumber::typeName() ||
|
||||
dataType == QgsProcessingParameterRange::typeName() ||
|
||||
dataType == QgsProcessingParameterColor::typeName() ||
|
||||
dataType == QgsProcessingOutputNumber::typeName() ||
|
||||
dataType == QgsProcessingParameterDistance::typeName() ||
|
||||
dataType == QgsProcessingParameterDuration::typeName() ||
|
||||
dataType == QgsProcessingParameterScale::typeName()
|
||||
|
||||
) {
|
||||
return QColor(34, 157, 214);
|
||||
} else
|
||||
|
||||
// Boolean type
|
||||
if(
|
||||
dataType == QgsProcessingParameterBoolean::typeName() ||
|
||||
dataType == QgsProcessingOutputBoolean::typeName()
|
||||
) {
|
||||
return QColor(51, 201, 28);
|
||||
} else
|
||||
|
||||
// Vector types
|
||||
if(
|
||||
dataType == QgsProcessingParameterPoint::typeName() ||
|
||||
dataType == QgsProcessingParameterGeometry::typeName() ||
|
||||
dataType == QgsProcessingParameterVectorLayer::typeName() ||
|
||||
dataType == QgsProcessingParameterMeshLayer::typeName() ||
|
||||
dataType == QgsProcessingParameterPointCloudLayer::typeName() ||
|
||||
dataType == QgsProcessingOutputVectorLayer::typeName() ||
|
||||
dataType == QgsProcessingOutputPointCloudLayer::typeName() ||
|
||||
dataType == QgsProcessingParameterExtent::typeName() ||
|
||||
dataType == QgsProcessingOutputVectorTileLayer::typeName() ||
|
||||
dataType == QgsProcessingParameterPointCloudDestination::typeName() ||
|
||||
dataType == QgsProcessingParameterVectorTileDestination::typeName() ||
|
||||
dataType == QgsProcessingParameterVectorDestination::typeName() ||
|
||||
dataType == QgsProcessingParameterFeatureSource::typeName()
|
||||
) {
|
||||
return QColor(180, 180, 0);
|
||||
} else
|
||||
|
||||
// Raster type
|
||||
if(
|
||||
dataType == QgsProcessingParameterRasterLayer::typeName() ||
|
||||
dataType == QgsProcessingOutputRasterLayer::typeName()
|
||||
|
||||
) {
|
||||
return QColor(0, 180, 180);
|
||||
} else
|
||||
|
||||
// enum
|
||||
if(
|
||||
dataType == QgsProcessingParameterEnum::typeName()
|
||||
) {
|
||||
return QColor(128, 68, 201);
|
||||
} else
|
||||
|
||||
// String and datetime types
|
||||
if(
|
||||
dataType == QgsProcessingParameterString::typeName() ||
|
||||
dataType == QgsProcessingParameterDateTime::typeName() ||
|
||||
dataType == QgsProcessingParameterCrs::typeName() ||
|
||||
dataType == QgsProcessingOutputHtml::typeName() ||
|
||||
dataType == QgsProcessingOutputString::typeName()
|
||||
|
||||
) {
|
||||
return QColor(100, 100, 255);
|
||||
} else
|
||||
|
||||
// filesystem types
|
||||
if(
|
||||
dataType == QgsProcessingParameterFile::typeName() ||
|
||||
dataType == QgsProcessingOutputFolder::typeName() ||
|
||||
dataType == QgsProcessingOutputFile::typeName() ||
|
||||
dataType == QgsProcessingParameterFolderDestination::typeName() ||
|
||||
dataType == QgsProcessingParameterFeatureSink::typeName() ||
|
||||
dataType == QgsProcessingParameterRasterDestination::typeName() ||
|
||||
dataType == QgsProcessingParameterFileDestination::typeName()
|
||||
) {
|
||||
return QColor(80, 80, 80);
|
||||
} else
|
||||
|
||||
// Expression type
|
||||
if(dataType == QgsProcessingParameterExpression::typeName()) {
|
||||
return QColor(180, 80, 180);
|
||||
} else
|
||||
|
||||
// Other Layer types
|
||||
if(
|
||||
dataType == QgsProcessingParameterMultipleLayers::typeName() ||
|
||||
dataType == QgsProcessingParameterMapLayer::typeName() ||
|
||||
dataType == QgsProcessingParameterAnnotationLayer::typeName() ||
|
||||
dataType == QgsProcessingOutputMultipleLayers::typeName()
|
||||
|
||||
) {
|
||||
return QColor(128, 128, 0);
|
||||
} else
|
||||
|
||||
// Default color, applies for:
|
||||
// QgsProcessingParameterField
|
||||
// QgsProcessingParameterMapTheme
|
||||
// QgsProcessingParameterBand
|
||||
// QgsProcessingParameterLayout
|
||||
// QgsProcessingParameterLayoutItem
|
||||
// QgsProcessingParameterCoordinateOperation
|
||||
// QgsProcessingParameterAuthConfig // config
|
||||
// QgsProcessingParameterDatabaseSchema
|
||||
// QgsProcessingParameterDatabaseTable
|
||||
// QgsProcessingParameterProviderConnection
|
||||
// QgsProcessingParameterPointCloudAttribute
|
||||
// QgsProcessingOutputVariant
|
||||
// QgsProcessingOutputConditionalBranch
|
||||
{
|
||||
return QColor(128, 128, 128);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool QgsModelDesignerSocketGraphicItem::isDefaultParamValue() {
|
||||
if (!mComponent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QgsProcessingModelChildAlgorithm *child = dynamic_cast<const QgsProcessingModelChildAlgorithm *>( mComponent );
|
||||
|
||||
if (!child) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isDefaultValue = true;
|
||||
|
||||
// We can only know if the socket should be filled if the algorithm is non null
|
||||
if (child->algorithm()) {
|
||||
switch ( mEdge )
|
||||
{
|
||||
// Input params
|
||||
case Qt::TopEdge:
|
||||
{
|
||||
QgsProcessingParameterDefinitions params = child->algorithm()->parameterDefinitions();
|
||||
|
||||
if ( mIndex > (params.length() - 1) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
const QgsProcessingParameterDefinition* param = params.at( mIndex );
|
||||
QString name = param->name();
|
||||
|
||||
QgsProcessingModelChildParameterSources paramSources = child->parameterSources().value(name);
|
||||
if (paramSources.size() == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// The default value can only happen in the case of the parameter uses a static value
|
||||
if (paramSources[0].getSourceType() != Qgis::ProcessingModelChildParameterSource::StaticValue) {
|
||||
isDefaultValue = false;
|
||||
break;
|
||||
}
|
||||
|
||||
isDefaultValue = paramSources[0].staticValue() == param->defaultValue();
|
||||
break;
|
||||
}
|
||||
|
||||
// Ouputs
|
||||
case Qt::BottomEdge:
|
||||
{
|
||||
|
||||
break;
|
||||
}
|
||||
case Qt::LeftEdge:
|
||||
case Qt::RightEdge:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isDefaultValue;
|
||||
}
|
||||
|
||||
///@endcond
|
||||
|
@ -158,6 +158,8 @@ class GUI_EXPORT QgsModelDesignerSocketGraphicItem : public QgsModelDesignerFlat
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static QColor typeToColorLookup(QString dataType);
|
||||
|
||||
/**
|
||||
* Constructor for QgsModelDesignerSocketGraphicItem, with the specified \a parent item.
|
||||
*
|
||||
@ -170,7 +172,7 @@ class GUI_EXPORT QgsModelDesignerSocketGraphicItem : public QgsModelDesignerFlat
|
||||
|
||||
void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr ) override;
|
||||
/**
|
||||
* Returns the index of this socket in either QgsModelDesignerSocketGraphicItem::mInSockets
|
||||
* Returns the index of this socket in either QgsModelDesignerSocketGraphicItem::mInSockets
|
||||
* or QgsModelDesignerSocketGraphicItem::mOutSockets array
|
||||
*/
|
||||
int index() const { return mIndex; };
|
||||
@ -184,7 +186,7 @@ class GUI_EXPORT QgsModelDesignerSocketGraphicItem : public QgsModelDesignerFlat
|
||||
|
||||
/**
|
||||
* Returns whether the socket is an input socket or not
|
||||
*
|
||||
*
|
||||
* Convenient function around mEdge member
|
||||
*/
|
||||
bool isInput() const { return mEdge == Qt::TopEdge; };
|
||||
@ -195,6 +197,11 @@ class GUI_EXPORT QgsModelDesignerSocketGraphicItem : public QgsModelDesignerFlat
|
||||
/** Return the parent graphic item associated to the socket */
|
||||
QgsModelComponentGraphicItem *componentItem() { return mComponentItem; };
|
||||
|
||||
/* Returns the color of the socket based on the type of data the param corresponds to */
|
||||
QColor getColor();
|
||||
|
||||
/* Returns whether the param value bear the default param value */
|
||||
bool isDefaultParamValue();
|
||||
signals:
|
||||
|
||||
|
||||
@ -203,6 +210,8 @@ class GUI_EXPORT QgsModelDesignerSocketGraphicItem : public QgsModelDesignerFlat
|
||||
QgsProcessingModelComponent *mComponent = nullptr;
|
||||
int mIndex = -1;
|
||||
Qt::Edge mEdge = Qt::Edge::TopEdge;
|
||||
QColor mSocketColor = QColor( 200, 200, 200 );
|
||||
float mSocketOutlineWidth = 1.5;
|
||||
};
|
||||
|
||||
///@endcond
|
||||
|
Loading…
x
Reference in New Issue
Block a user