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