QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 "qgssettings.h"
22#include "qgshelp.h"
23
24#include <QTreeWidgetItem>
25#include <QComboBox>
26#include <QRadioButton>
27
28QgsAddAttributeFormContainerDialog::QgsAddAttributeFormContainerDialog( QgsVectorLayer *lyr, const QList<ContainerPair> &existingContainerList, QTreeWidgetItem *currentTab, QWidget *parent )
29 : QDialog( parent )
30 , mLayer( lyr )
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 ( container.second == currentTab )
49 {
50 mParentCombo->setCurrentIndex( i );
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 nullptr;
76
77 if ( !mParentCombo->currentData().isValid() )
78 return nullptr;
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 {
100
102 QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), mColumnCountSpinBox->value() );
103 break;
105 QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), mColumnCountSpinBox->value() );
106 break;
108 break;
109 }
110 }
111
112 QDialog::accept();
113}
114
115void QgsAddAttributeFormContainerDialog::showHelp()
116{
117 QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#the-drag-and-drop-designer" ) );
118}
119
120void QgsAddAttributeFormContainerDialog::containerTypeChanged()
121{
122 const Qgis::AttributeEditorContainerType type = mTypeCombo->currentData().value< Qgis::AttributeEditorContainerType >();
123 switch ( type )
124 {
126 mParentCombo->show();
127 mLabelParent->show();
128 mColumnsLabel->show();
129 mColumnCountSpinBox->show();
130 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), 1 ).toInt() );
131 break;
133 mParentCombo->hide();
134 mLabelParent->hide();
135 mColumnsLabel->show();
136 mColumnCountSpinBox->show();
137 mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), 1 ).toInt() );
138 break;
140 mParentCombo->show();
141 mLabelParent->show();
142 mColumnsLabel->hide();
143 mColumnCountSpinBox->hide();
144 break;
145 }
146}
AttributeEditorContainerType
Attribute editor container types.
Definition qgis.h:5073
@ 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.