QGIS API Documentation 3.41.0-Master (3440c17df1d)
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 "qgsvectorlayer.h"
20#include "qgsaddtaborgroup.h"
21#include "moc_qgsaddtaborgroup.cpp"
22#include "qgssettings.h"
23#include "qgshelp.h"
24
25#include <QTreeWidgetItem>
26#include <QComboBox>
27#include <QRadioButton>
28
29QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVectorLayer *lyr, const QList<ContainerPair> &existingContainerList, QTreeWidgetItem *currentTab, QWidget *parent )
30 : QDialog( parent )
31 , mLayer( lyr )
32 , mExistingContainers( existingContainerList )
33{
34 setupUi( this );
35
36 mTypeCombo->addItem( tr( "Tab" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) );
37 mTypeCombo->addItem( tr( "Group Box" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) );
38 mTypeCombo->addItem( tr( "Row" ), QVariant::fromValue( Qgis::AttributeEditorContainerType::Row ) );
39
40 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::Tab ) ) );
41
42 mParentCombo->addItem( QString() );
43 if ( !mExistingContainers.isEmpty() )
44 {
45 int i = 0;
46 for ( const ContainerPair &container : std::as_const( mExistingContainers ) )
47 {
48 mParentCombo->addItem( container.first, i );
49 if ( container.second == currentTab )
50 {
51 mParentCombo->setCurrentIndex( i );
52 mTypeCombo->setCurrentIndex( mTypeCombo->findData( QVariant::fromValue( Qgis::AttributeEditorContainerType::GroupBox ) ) );
53 }
54 ++i;
55 }
56 }
57
58 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAddAttributeFormContainerDialog::showHelp );
59
60 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), 1 ).toInt() );
61
62 setWindowTitle( tr( "Add Container for %1" ).arg( mLayer->name() ) );
63
64 connect( mTypeCombo, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsAddAttributeFormContainerDialog::containerTypeChanged );
65 containerTypeChanged();
66}
67
69{
70 return mName->text();
71}
72
74{
76 return nullptr;
77
78 if ( !mParentCombo->currentData().isValid() )
79 return nullptr;
80
81 const ContainerPair tab = mExistingContainers.at( mParentCombo->currentData().toInt() );
82 return tab.second;
83}
84
86{
87 return mColumnCountSpinBox->value();
88}
89
94
96{
97 if ( mColumnCountSpinBox->value() > 0 )
98 {
99 switch ( containerType() )
100 {
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:5081
@ Row
A row of editors (horizontal layout)
QPair< QString, QTreeWidgetItem * > ContainerPair
Qgis::AttributeEditorContainerType containerType() const
Returns the container type.
QString name()
Returns the name of the tab or group.
void accept() override
Accepts the dialog.
QgsAddAttributeFormContainerDialog(QgsVectorLayer *lyr, const QList< ContainerPair > &existingContainerList, QTreeWidgetItem *currentTab=nullptr, QWidget *parent=nullptr)
constructor
QList< ContainerPair > mExistingContainers
QTreeWidgetItem * parentContainerItem()
Returns tree item corresponding to the selected parent container.
int columnCount() const
Returns the column count.
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:80
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
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 data sets.