QGIS API Documentation 3.43.0-Master (2366440f66a)
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 "qgsvectorlayer.h"
20#include "qgsaddtaborgroup.h"
21#include "moc_qgsaddtaborgroup.cpp"
22#include "qgssettings.h"
23#include "qgshelp.h"
24
25#include <QComboBox>
26#include <QRadioButton>
27
28QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVectorLayer *layer, const QList<ContainerPair> &existingContainerList, QModelIndex &currentItemIndex, QWidget *parent )
29 : QDialog( parent )
30 , mLayer( layer )
31 , mExistingContainers( existingContainerList )
32{
33 setupUi( this );
34
35 mTypeCombo->addItem( tr( "Tab" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) );
36 mTypeCombo->addItem( tr( "Group Box" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) );
37 mTypeCombo->addItem( tr( "Row" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Row ) );
38
39 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) ) );
40
41 mParentCombo->addItem( QString() );
42 if ( !mExistingContainers.isEmpty() )
43 {
44 int i = 0;
45 for ( const ContainerPair &container : std::as_const( mExistingContainers ) )
46 {
47 mParentCombo->addItem( container.first, i );
48 if ( currentItemIndex.isValid() && container.second == currentItemIndex )
49 {
50 mParentCombo->setCurrentIndex( i + 1 ); // Take empty item into account
51 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) ) );
52 }
53 ++i;
54 }
55 }
56
57 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAddAttributeFormContainerDialog::showHelp );
58
59 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), 1 ).toInt() );
60
61 setWindowTitle( tr( "Add Container for %1" ).arg( mLayer->name() ) );
62
63 connect( mTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsAddAttributeFormContainerDialog::containerTypeChanged );
64 containerTypeChanged();
65}
66
68{
69 return mName->text();
70}
71
73{
75 return QModelIndex();
76
77 if ( !mParentCombo->currentData().isValid() )
78 return QModelIndex();
79
80 const ContainerPair tab = mExistingContainers.at( mParentCombo->currentData().toInt() );
81 return tab.second;
82}
83
85{
86 return mColumnCountSpinBox->value();
87}
88
93
95{
96 if ( mColumnCountSpinBox->value() > 0 )
97 {
98 switch ( containerType() )
99 {
101 QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), mColumnCountSpinBox->value() );
102 break;
104 QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), mColumnCountSpinBox->value() );
105 break;
107 break;
108 }
109 }
110
111 QDialog::accept();
112}
113
114void QgsAddAttributeFormContainerDialog::showHelp()
115{
116 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#the-drag-and-drop-designer" ) );
117}
118
119void QgsAddAttributeFormContainerDialog::containerTypeChanged()
120{
121 const Qgis::AttributeEditorContainerType type = mTypeCombo->currentData().value<Qgis::AttributeEditorContainerType>();
122 switch ( type )
123 {
125 mParentCombo->show();
126 mLabelParent->show();
127 mColumnsLabel->show();
128 mColumnCountSpinBox->show();
129 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), 1 ).toInt() );
130 break;
132 mParentCombo->hide();
133 mLabelParent->hide();
134 mColumnsLabel->show();
135 mColumnCountSpinBox->show();
136 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), 1 ).toInt() );
137 break;
139 mParentCombo->show();
140 mLabelParent->show();
141 mColumnsLabel->hide();
142 mColumnCountSpinBox->hide();
143 break;
144 }
145}
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5279
@ Row
A row of editors (horizontal layout)
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:39
QString name
Definition qgsmaplayer.h:81
Stores settings for use within QGIS.
Definition qgssettings.h:65
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.