QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsaddtaborgroup.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsaddtaborgroup.h
3 Add a tab or a group for the tab and group display of fields
4 -------------------
5 begin : 2012-07-30
6 copyright : (C) 2012 by Denis Rouzaud
7 email : denis dot rouzaud at gmail dot com
8***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#include "qgsaddtaborgroup.h"
20
21#include "qgshelp.h"
22#include "qgssettings.h"
23#include "qgsvectorlayer.h"
24
25#include <QComboBox>
26#include <QRadioButton>
27#include <QString>
28
29#include "moc_qgsaddtaborgroup.cpp"
30
31using namespace Qt::StringLiterals;
32
33QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVectorLayer *layer, const QList<ContainerPair> &existingContainerList, QModelIndex &currentItemIndex, QWidget *parent )
34 : QDialog( parent )
35 , mLayer( layer )
36 , mExistingContainers( existingContainerList )
37{
38 setupUi( this );
39
40 mTypeCombo->addItem( tr( "Tab" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) );
41 mTypeCombo->addItem( tr( "Group Box" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) );
42 mTypeCombo->addItem( tr( "Row" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Row ) );
43
44 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) ) );
45
46 mParentCombo->addItem( QString() );
47 if ( !mExistingContainers.isEmpty() )
48 {
49 int i = 0;
50 for ( const ContainerPair &container : std::as_const( mExistingContainers ) )
51 {
52 mParentCombo->addItem( container.first, i );
53 if ( currentItemIndex.isValid() && container.second == currentItemIndex )
54 {
55 mParentCombo->setCurrentIndex( i + 1 ); // Take empty item into account
56 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) ) );
57 }
58 ++i;
59 }
60 }
61
62 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAddAttributeFormContainerDialog::showHelp );
63
64 mColumnCountSpinBox->setValue( QgsSettings().value( u"/qgis/attributeForm/defaultTabColumnCount"_s, 1 ).toInt() );
65
66 setWindowTitle( tr( "Add Container for %1" ).arg( mLayer->name() ) );
67
68 connect( mTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsAddAttributeFormContainerDialog::containerTypeChanged );
69 containerTypeChanged();
70}
71
73{
74 return mName->text();
75}
76
78{
80 return QModelIndex();
81
82 if ( !mParentCombo->currentData().isValid() )
83 return QModelIndex();
84
85 const ContainerPair tab = mExistingContainers.at( mParentCombo->currentData().toInt() );
86 return tab.second;
87}
88
90{
91 return mColumnCountSpinBox->value();
92}
93
98
100{
101 if ( mColumnCountSpinBox->value() > 0 )
102 {
103 switch ( containerType() )
104 {
106 QgsSettings().setValue( u"/qgis/attributeForm/defaultGroupColumnCount"_s, mColumnCountSpinBox->value() );
107 break;
109 QgsSettings().setValue( u"/qgis/attributeForm/defaultTabColumnCount"_s, mColumnCountSpinBox->value() );
110 break;
112 break;
113 }
114 }
115
116 QDialog::accept();
117}
118
119void QgsAddAttributeFormContainerDialog::showHelp()
120{
121 QgsHelp::openHelp( u"working_with_vector/vector_properties.html#the-drag-and-drop-designer"_s );
122}
123
124void QgsAddAttributeFormContainerDialog::containerTypeChanged()
125{
126 const Qgis::AttributeEditorContainerType type = mTypeCombo->currentData().value<Qgis::AttributeEditorContainerType>();
127 switch ( type )
128 {
130 mParentCombo->show();
131 mLabelParent->show();
132 mColumnsLabel->show();
133 mColumnCountSpinBox->show();
134 mColumnCountSpinBox->setValue( QgsSettings().value( u"/qgis/attributeForm/defaultGroupColumnCount"_s, 1 ).toInt() );
135 break;
137 mParentCombo->hide();
138 mLabelParent->hide();
139 mColumnsLabel->show();
140 mColumnCountSpinBox->show();
141 mColumnCountSpinBox->setValue( QgsSettings().value( u"/qgis/attributeForm/defaultTabColumnCount"_s, 1 ).toInt() );
142 break;
144 mParentCombo->show();
145 mLabelParent->show();
146 mColumnsLabel->hide();
147 mColumnCountSpinBox->hide();
148 break;
149 }
150}
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5736
@ Row
A row of editors (horizontal layout).
Definition qgis.h:5739
QPair< QString, QModelIndex > ContainerPair
QModelIndex parentContainerItem() const
Returns tree model index corresponding to the selected parent container.
QgsAddAttributeFormContainerDialog(QgsVectorLayer *layer, const QList< ContainerPair > &existingContainerList, QModelIndex &currentItemIndex, QWidget *parent=nullptr)
constructor
Qgis::AttributeEditorContainerType containerType() const
Returns the container type.
QString name()
Returns the name of the container.
void accept() override
Accepts the dialog.
int columnCount() const
Returns the column count.
QList< ContainerPair > mExistingContainers
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
Stores settings for use within QGIS.
Definition qgssettings.h:68
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Represents a vector layer which manages a vector based dataset.