QGIS API Documentation  3.27.0-Master (0e23467727)
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 "qgsapplication.h"
20 #include "qgsvectorlayer.h"
21 #include "qgsaddtaborgroup.h"
22 #include "qgssettings.h"
23 
24 #include <QTreeWidgetItem>
25 #include <QComboBox>
26 #include <QRadioButton>
27 
28 QgsAddTabOrGroup::QgsAddTabOrGroup( QgsVectorLayer *lyr, const QList < TabPair > &tabList, QTreeWidgetItem *currentTab, QWidget *parent )
29  : QDialog( parent )
30  , mLayer( lyr )
31  , mTabs( tabList )
32 {
33  setupUi( this );
34  connect( mGroupButton, &QRadioButton::toggled, this, &QgsAddTabOrGroup::mGroupButton_toggled );
35  connect( mTabButton, &QRadioButton::toggled, this, &QgsAddTabOrGroup::mTabButton_toggled );
36 
37  mTabButton->setChecked( true );
38  mTabList->setEnabled( false );
39  if ( !mTabs.isEmpty() )
40  {
41  int i = 0;
42  const auto constMTabs = mTabs;
43  for ( const TabPair &tab : constMTabs )
44  {
45  mTabList->addItem( tab.first, i );
46  if ( tab.second == currentTab )
47  {
48  mTabList->setCurrentIndex( i );
49  mGroupButton->setChecked( true );
50  }
51  ++i;
52  }
53  }
54  else
55  {
56  mGroupButton->setEnabled( false );
57  }
58 
59  connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsAddTabOrGroup::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 
67 {
68  return mName->text();
69 }
70 
71 QTreeWidgetItem *QgsAddTabOrGroup::tab()
72 {
73  const TabPair tab = mTabs.at( mTabList->currentData().toInt() );
74  return tab.second;
75 }
76 
78 {
79  return mColumnCountSpinBox->value();
80 }
81 
83 {
84  return mTabButton->isChecked();
85 }
86 
88 {
89  if ( mColumnCountSpinBox->value() > 0 )
90  {
91  if ( mGroupButton->isChecked() )
92  {
93  QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), mColumnCountSpinBox->value() );
94  }
95  else
96  {
97  QgsSettings().setValue( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), mColumnCountSpinBox->value() );
98  }
99  }
100 
101  QDialog::accept();
102 }
103 
104 void QgsAddTabOrGroup::mGroupButton_toggled( bool checked )
105 {
106  mTabList->setEnabled( checked );
107 
108  if ( checked )
109  {
110  mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultGroupColumnCount" ), 1 ).toInt() );
111  }
112 }
113 
114 void QgsAddTabOrGroup::mTabButton_toggled( bool checked )
115 {
116  mTabList->setEnabled( !checked );
117  if ( checked )
118  mColumnCountSpinBox->setValue( QgsSettings().value( QStringLiteral( "/qgis/attributeForm/defaultTabColumnCount" ), 1 ).toInt() );
119 }
120 
121 void QgsAddTabOrGroup::showHelp()
122 {
123  QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#the-drag-and-drop-designer" ) );
124 }
QgsAddTabOrGroup(QgsVectorLayer *lyr, const QList< TabPair > &tabList, QTreeWidgetItem *currentTab=nullptr, QWidget *parent=nullptr)
constructor
QPair< QString, QTreeWidgetItem * > TabPair
QgsVectorLayer * mLayer
QTreeWidgetItem * tab()
Returns tree item corresponding to the added tab.
void accept() override
Accepts the dialog.
int columnCount() const
Returns the column count.
bool tabButtonIsChecked()
Returns whether the tab button is checked.
QString name()
Returns the name of the tab or group.
QList< TabPair > mTabs
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition: qgshelp.cpp:36
QString name
Definition: qgsmaplayer.h:76
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
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.