QGIS API Documentation  2.99.0-Master (6a61179)
qgsattributedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributedialog.cpp - description
3  -------------------
4  begin : October 2004
5  copyright : (C) 2004 by Marco Hugentobler
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsattributedialog.h"
19 
20 #include "qgsattributeform.h"
21 #include "qgshighlight.h"
22 #include "qgsapplication.h"
23 #include "qgsactionmenu.h"
24 
25 #include <QSettings>
26 
27 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QWidget* parent, bool showDialogButtons, const QgsAttributeEditorContext &context )
28  : QDialog( parent )
29  , mHighlight( nullptr )
30  , mOwnedFeature( featureOwner ? thepFeature : nullptr )
31 {
32  init( vl, thepFeature, context, showDialogButtons );
33 }
34 
36 {
37  if ( mHighlight )
38  {
39  mHighlight->hide();
40  delete mHighlight;
41  }
42 
43  if ( mOwnedFeature )
44  delete mOwnedFeature;
45 
46  saveGeometry();
47 }
48 
50 {
51  QSettings().setValue( mSettingsPath + "geometry", QDialog::saveGeometry() );
52 }
53 
55 {
56  QDialog::restoreGeometry( QSettings().value( mSettingsPath + "geometry" ).toByteArray() );
57 }
58 
60 {
61  delete mHighlight;
62 
63  mHighlight = h;
64 }
65 
67 {
68  mAttributeForm->save();
69  QDialog::accept();
70 }
71 
73 {
74  QDialog::show();
75  raise();
76  activateWindow();
77 }
78 
80 {
81  // Delete any actions on other layers that may have been triggered from this dialog
82  if ( mAttributeForm->mode() == QgsAttributeForm::AddFeatureMode )
83  mTrackedVectorLayerTools.rollback();
84 
85  QDialog::reject();
86 }
87 
88 void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext& context, bool showDialogButtons )
89 {
90  QgsAttributeEditorContext trackedContext = context;
91  setWindowTitle( tr( "%1 - Feature Attributes" ).arg( layer->name() ) );
92  setLayout( new QGridLayout() );
93  layout()->setMargin( 0 );
94  mTrackedVectorLayerTools.setVectorLayerTools( trackedContext.vectorLayerTools() );
95  trackedContext.setVectorLayerTools( &mTrackedVectorLayerTools );
96  if ( showDialogButtons )
98 
99  mAttributeForm = new QgsAttributeForm( layer, *feature, trackedContext, this );
100  mAttributeForm->disconnectButtonBox();
101  layout()->addWidget( mAttributeForm );
102  QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
103  connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
104  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
105  connect( layer, SIGNAL( destroyed() ), this, SLOT( close() ) );
106 
107  QgsActionMenu* menu = new QgsActionMenu( layer, mAttributeForm->feature(), QStringLiteral( "AttributeTableRow" ), this );
108  if ( !menu->actions().isEmpty() )
109  {
110  QMenuBar* menuBar = new QMenuBar( this );
111  menuBar->addMenu( menu );
112  layout()->setMenuBar( menuBar );
113  }
114  else
115  {
116  delete menu;
117  }
118 
119  restoreGeometry();
120  focusNextChild();
121 }
122 
123 bool QgsAttributeDialog::event( QEvent* e )
124 {
125  if ( e->type() == QEvent::WindowActivate && mHighlight )
126  mHighlight->show();
127  else if ( e->type() == QEvent::WindowDeactivate && mHighlight )
128  mHighlight->hide();
129 
130  return QDialog::event( e );
131 }
const QgsVectorLayerTools * vectorLayerTools() const
void restoreGeometry()
Restores the size and position from the last time this dialog box was used.
This class contains context information for attribute editor widgets.
void saveGeometry()
Saves the size and position for the next time this dialog box will be used.
bool save()
Save all the values from the editors to the layer.
void setHighlight(QgsHighlight *h)
setHighlight
void setVectorLayerTools(QgsVectorLayerTools *vlTools)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:135
void setVectorLayerTools(const QgsVectorLayerTools *tools)
Set the vector layer tools that will be used to interact with the data.
void show()
Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form.
QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QWidget *parent=nullptr, bool showDialogButtons=true, const QgsAttributeEditorContext &context=QgsAttributeEditorContext())
Create an attribute dialog for a given layer and feature.
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:34
A class for highlight features on the map.
Definition: qgshighlight.h:35
void disconnectButtonBox()
Disconnects the button box (Ok/Cancel) from the accept/resetValues slots If this method is called...
void rollback()
Delete all features which have been added via this object.
virtual bool event(QEvent *e) override
Intercept window activate/deactive events to show/hide the highlighted feature.
void reject() override
void setFormMode(FormMode mode)
Sets the form mode.
Mode mode() const
Returns the current mode of the form.
const QgsFeature * feature()
const QgsFeature & feature()
QString name
Read property of QString layerName.
Definition: qgsmaplayer.h:53
void accept() override
Represents a vector layer which manages a vector based data sets.