QGIS API Documentation 3.99.0-Master (c22de0620c0)
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
21#include "qgscolorbutton.h"
22#include "qgsgui.h"
23
24#include <QDialogButtonBox>
25#include <QLabel>
26#include <QString>
27#include <QTextEdit>
28#include <QVBoxLayout>
29
30#include "moc_qgsmodelgroupboxdefinitionwidget.cpp"
31
32using namespace Qt::StringLiterals;
33
34//
35// QgsModelGroupBoxDefinitionPanelWidget
36//
37
38QgsModelGroupBoxDefinitionPanelWidget::QgsModelGroupBoxDefinitionPanelWidget( const QgsProcessingModelGroupBox &box, QWidget *parent )
40 , mBox( box )
41{
42 QVBoxLayout *commentLayout = new QVBoxLayout();
43 commentLayout->setContentsMargins( 0, 0, 0, 0 );
44 commentLayout->addWidget( new QLabel( tr( "Title" ) ) );
45 mCommentEdit = new QTextEdit();
46 mCommentEdit->setAcceptRichText( false );
47 mCommentEdit->setText( box.description() );
48 commentLayout->addWidget( mCommentEdit, 1 );
49
50 QHBoxLayout *hl = new QHBoxLayout();
51 hl->setContentsMargins( 0, 0, 0, 0 );
52 hl->addWidget( new QLabel( tr( "Color" ) ) );
53 mCommentColorButton = new QgsColorButton();
54 mCommentColorButton->setAllowOpacity( true );
55 mCommentColorButton->setWindowTitle( tr( "Comment Color" ) );
56 mCommentColorButton->setShowNull( true, tr( "Default" ) );
57
58 if ( box.color().isValid() )
59 mCommentColorButton->setColor( box.color() );
60 else
61 mCommentColorButton->setToNull();
62
63 hl->addWidget( mCommentColorButton );
64 commentLayout->addLayout( hl );
65
66 setLayout( commentLayout );
67
68 setPanelTitle( tr( "Group Box Properties" ) );
69 setObjectName( u"QgsModelGroupBoxDefinitionPanelWidget"_s );
70
71 mCommentEdit->setFocus();
72 mCommentEdit->selectAll();
73
74 connect( mCommentEdit, &QTextEdit::textChanged, this, &QgsPanelWidget::widgetChanged );
75 connect( mCommentColorButton, &QgsColorButton::colorChanged, this, &QgsPanelWidget::widgetChanged );
76}
77
78QgsProcessingModelGroupBox QgsModelGroupBoxDefinitionPanelWidget::groupBox() const
79{
80 QgsProcessingModelGroupBox box = mBox;
81 box.setColor( mCommentColorButton->isNull() ? QColor() : mCommentColorButton->color() );
82 box.setDescription( mCommentEdit->toPlainText() );
83 return box;
84}
85
86//
87// QgsModelGroupBoxDefinitionDialog
88//
89
90QgsModelGroupBoxDefinitionDialog::QgsModelGroupBoxDefinitionDialog( const QgsProcessingModelGroupBox &box, QWidget *parent )
91 : QDialog( parent )
92{
93 QVBoxLayout *commentLayout = new QVBoxLayout();
94 mWidget = new QgsModelGroupBoxDefinitionPanelWidget( box );
95 commentLayout->addWidget( mWidget, 1 );
96
97 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
98 connect( bbox, &QDialogButtonBox::accepted, this, &QgsModelGroupBoxDefinitionDialog::accept );
99 connect( bbox, &QDialogButtonBox::rejected, this, &QgsModelGroupBoxDefinitionDialog::reject );
100
101 commentLayout->addWidget( bbox );
102 setLayout( commentLayout );
103 setWindowTitle( tr( "Group Box Properties" ) );
104 setObjectName( u"QgsModelGroupBoxDefinitionWidget"_s );
106
107 connect( mWidget, &QgsPanelWidget::panelAccepted, this, &QgsModelGroupBoxDefinitionDialog::reject );
108}
109
110QgsProcessingModelGroupBox QgsModelGroupBoxDefinitionDialog::groupBox() const
111{
112 return mWidget->groupBox();
113}
A cross platform button subclass for selecting colors.
void colorChanged(const QColor &color)
Emitted whenever a new color is set 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:224
QgsModelGroupBoxDefinitionDialog(const QgsProcessingModelGroupBox &box, QWidget *parent=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.
A widget which allows users to specify the properties of a model group box.
QgsModelGroupBoxDefinitionPanelWidget(const QgsProcessingModelGroupBox &box, QWidget *parent=nullptr)
Constructor for QgsModelGroupBoxDefinitionPanelWidget, for the specified group box.
QgsProcessingModelGroupBox groupBox() const
Returns a new instance of the group box, using the current settings defined in the dialog.
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
void widgetChanged()
Emitted when the widget state changes.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
QgsProcessingModelConfigWidget(QWidget *parent=nullptr)
Constructor for QgsProcessingModelConfigWidget().