QGIS API Documentation 3.99.0-Master (8e76e220402)
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
34QgsModelGroupBoxDefinitionDialog::QgsModelGroupBoxDefinitionDialog( const QgsProcessingModelGroupBox &box, QWidget *parent )
35 : QDialog( parent )
36 , mBox( box )
37{
38 QVBoxLayout *commentLayout = new QVBoxLayout();
39 commentLayout->addWidget( new QLabel( tr( "Title" ) ) );
40 mCommentEdit = new QTextEdit();
41 mCommentEdit->setAcceptRichText( false );
42 mCommentEdit->setText( box.description() );
43 commentLayout->addWidget( mCommentEdit, 1 );
44
45 QHBoxLayout *hl = new QHBoxLayout();
46 hl->setContentsMargins( 0, 0, 0, 0 );
47 hl->addWidget( new QLabel( tr( "Color" ) ) );
48 mCommentColorButton = new QgsColorButton();
49 mCommentColorButton->setAllowOpacity( true );
50 mCommentColorButton->setWindowTitle( tr( "Comment Color" ) );
51 mCommentColorButton->setShowNull( true, tr( "Default" ) );
52
53 if ( box.color().isValid() )
54 mCommentColorButton->setColor( box.color() );
55 else
56 mCommentColorButton->setToNull();
57
58 hl->addWidget( mCommentColorButton );
59 commentLayout->addLayout( hl );
60
61 QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
62 connect( bbox, &QDialogButtonBox::accepted, this, &QgsModelGroupBoxDefinitionDialog::accept );
63 connect( bbox, &QDialogButtonBox::rejected, this, &QgsModelGroupBoxDefinitionDialog::reject );
64
65 commentLayout->addWidget( bbox );
66 setLayout( commentLayout );
67 setWindowTitle( tr( "Group Box Properties" ) );
68 setObjectName( u"QgsModelGroupBoxDefinitionWidget"_s );
70
71 mCommentEdit->setFocus();
72 mCommentEdit->selectAll();
73}
74
75QgsProcessingModelGroupBox QgsModelGroupBoxDefinitionDialog::groupBox() const
76{
77 QgsProcessingModelGroupBox box = mBox;
78 box.setColor( mCommentColorButton->isNull() ? QColor() : mCommentColorButton->color() );
79 box.setDescription( mCommentEdit->toPlainText() );
80 return box;
81}
A cross platform button subclass for selecting colors.
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 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.