QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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#include "moc_qgsmodelgroupboxdefinitionwidget.cpp"
21
22#include "qgscolorbutton.h"
23#include "qgsgui.h"
24#include <QVBoxLayout>
25#include <QTextEdit>
26#include <QDialogButtonBox>
27#include <QLabel>
28
30 QWidget *parent )
31 : QDialog( parent )
32 , mBox( box )
33{
34 QVBoxLayout *commentLayout = new QVBoxLayout();
35 commentLayout->addWidget( new QLabel( tr( "Title" ) ) );
36 mCommentEdit = new QTextEdit();
37 mCommentEdit->setAcceptRichText( false );
38 mCommentEdit->setText( box.description() );
39 commentLayout->addWidget( mCommentEdit, 1 );
40
41 QHBoxLayout *hl = new QHBoxLayout();
42 hl->setContentsMargins( 0, 0, 0, 0 );
43 hl->addWidget( new QLabel( tr( "Color" ) ) );
44 mCommentColorButton = new QgsColorButton();
45 mCommentColorButton->setAllowOpacity( true );
46 mCommentColorButton->setWindowTitle( tr( "Comment Color" ) );
47 mCommentColorButton->setShowNull( true, tr( "Default" ) );
48
49 if ( box.color().isValid() )
50 mCommentColorButton->setColor( box.color() );
51 else
52 mCommentColorButton->setToNull();
53
54 hl->addWidget( mCommentColorButton );
55 commentLayout->addLayout( hl );
56
57 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
58 connect( bbox, &QDialogButtonBox::accepted, this, &QgsModelGroupBoxDefinitionDialog::accept );
59 connect( bbox, &QDialogButtonBox::rejected, this, &QgsModelGroupBoxDefinitionDialog::reject );
60
61 commentLayout->addWidget( bbox );
62 setLayout( commentLayout );
63 setWindowTitle( tr( "Group Box Properties" ) );
64 setObjectName( QStringLiteral( "QgsModelGroupBoxDefinitionWidget" ) );
66
67 mCommentEdit->setFocus();
68 mCommentEdit->selectAll();
69}
70
71QgsProcessingModelGroupBox QgsModelGroupBoxDefinitionDialog::groupBox() const
72{
73 QgsProcessingModelGroupBox box = mBox;
74 box.setColor( mCommentColorButton->isNull() ? QColor() : mCommentColorButton->color() );
75 box.setDescription( mCommentEdit->toPlainText() );
76 return box;
77}
78
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:209
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.