QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
qgsmodelgroupboxdefinitionwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmodelgroupboxdefinitionwidget.cpp
3 ------------------------------------------
4 begin : March 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
18
20
21#include "qgscolorbutton.h"
22#include "qgsgui.h"
23#include <QVBoxLayout>
24#include <QTextEdit>
25#include <QDialogButtonBox>
26#include <QLabel>
27
29 QWidget *parent )
30 : QDialog( parent )
31 , mBox( box )
32{
33 QVBoxLayout *commentLayout = new QVBoxLayout();
34 commentLayout->addWidget( new QLabel( tr( "Title" ) ) );
35 mCommentEdit = new QTextEdit();
36 mCommentEdit->setAcceptRichText( false );
37 mCommentEdit->setText( box.description() );
38 commentLayout->addWidget( mCommentEdit, 1 );
39
40 QHBoxLayout *hl = new QHBoxLayout();
41 hl->setContentsMargins( 0, 0, 0, 0 );
42 hl->addWidget( new QLabel( tr( "Color" ) ) );
43 mCommentColorButton = new QgsColorButton();
44 mCommentColorButton->setAllowOpacity( true );
45 mCommentColorButton->setWindowTitle( tr( "Comment Color" ) );
46 mCommentColorButton->setShowNull( true, tr( "Default" ) );
47
48 if ( box.color().isValid() )
49 mCommentColorButton->setColor( box.color() );
50 else
51 mCommentColorButton->setToNull();
52
53 hl->addWidget( mCommentColorButton );
54 commentLayout->addLayout( hl );
55
56 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
57 connect( bbox, &QDialogButtonBox::accepted, this, &QgsModelGroupBoxDefinitionDialog::accept );
58 connect( bbox, &QDialogButtonBox::rejected, this, &QgsModelGroupBoxDefinitionDialog::reject );
59
60 commentLayout->addWidget( bbox );
61 setLayout( commentLayout );
62 setWindowTitle( tr( "Group Box Properties" ) );
63 setObjectName( QStringLiteral( "QgsModelGroupBoxDefinitionWidget" ) );
65
66 mCommentEdit->setFocus();
67 mCommentEdit->selectAll();
68}
69
70QgsProcessingModelGroupBox QgsModelGroupBoxDefinitionDialog::groupBox() const
71{
72 QgsProcessingModelGroupBox box = mBox;
73 box.setColor( mCommentColorButton->isNull() ? QColor() : mCommentColorButton->color() );
74 box.setDescription( mCommentEdit->toPlainText() );
75 return box;
76}
77
A cross platform button subclass for selecting colors.
void setShowNull(bool showNull, const QString &nullString=QString())
Sets whether a set to null (clear) option is shown in the button's drop-down menu.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color.
void setToNull()
Sets color to null.
bool isNull() const
Returns true if the current color is null.
void setColor(const QColor &color)
Sets the current color for the button.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:193
QgsModelGroupBoxDefinitionDialog(const QgsProcessingModelGroupBox &box, QWidget *parent SIP_TRANSFERTHIS=nullptr)
Constructor for QgsModelGroupBoxDefinitionWidget, for the specified group box.
QgsProcessingModelGroupBox groupBox() const
Returns a new instance of the group box, using the current settings defined in the dialog.