QGIS API Documentation  2.14.11-Essen
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 : marco.hugentobler@autoform.ch
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 
28 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, const QgsDistanceArea &myDa, QWidget* parent, bool showDialogButtons )
29  : QDialog( parent )
30  , mHighlight( nullptr )
31  , mOwnedFeature( featureOwner ? thepFeature : nullptr )
32 {
34  context.setDistanceArea( myDa );
35 
36  init( vl, thepFeature, context );
37 
38  if ( !showDialogButtons )
39  mAttributeForm->hideButtonBox();
40 }
41 
42 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QWidget* parent, bool showDialogButtons, const QgsAttributeEditorContext &context )
43  : QDialog( parent )
44  , mHighlight( nullptr )
45  , mOwnedFeature( featureOwner ? thepFeature : nullptr )
46 {
47  init( vl, thepFeature, context );
48 
49  if ( !showDialogButtons )
50  mAttributeForm->hideButtonBox();
51 }
52 
54 {
55  if ( mHighlight )
56  {
57  mHighlight->hide();
58  delete mHighlight;
59  }
60 
61  if ( mOwnedFeature )
62  delete mOwnedFeature;
63 
64  saveGeometry();
65 }
66 
68 {
69  QSettings().setValue( mSettingsPath + "geometry", QDialog::saveGeometry() );
70 }
71 
73 {
74  QDialog::restoreGeometry( QSettings().value( mSettingsPath + "geometry" ).toByteArray() );
75 }
76 
78 {
79  delete mHighlight;
80 
81  mHighlight = h;
82 }
83 
85 {
86  mAttributeForm->save();
88 }
89 
91 {
92  QDialog::show();
93  raise();
95 }
96 
97 void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext &context )
98 {
99  setWindowTitle( tr( "%1 - Feature Attributes" ).arg( layer->name() ) );
100  setLayout( new QGridLayout() );
101  layout()->setMargin( 0 );
102  mAttributeForm = new QgsAttributeForm( layer, *feature, context, this );
103  mAttributeForm->disconnectButtonBox();
104  layout()->addWidget( mAttributeForm );
105  QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
106  connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
107  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
108  connect( layer, SIGNAL( layerDeleted() ), this, SLOT( close() ) );
109 
110  QgsActionMenu* menu = new QgsActionMenu( layer, &mAttributeForm->feature(), this );
111  if ( !menu->actions().isEmpty() )
112  {
113  QMenuBar* menuBar = new QMenuBar( this );
114  menuBar->addMenu( menu );
115  layout()->setMenuBar( menuBar );
116  }
117  else
118  {
119  delete menu;
120  }
121 
122  restoreGeometry();
123  focusNextChild();
124 }
125 
127 {
128  if ( e->type() == QEvent::WindowActivate && mHighlight )
129  mHighlight->show();
130  else if ( e->type() == QEvent::WindowDeactivate && mHighlight )
131  mHighlight->hide();
132 
133  return QDialog::event( e );
134 }
QLayout * layout() const
void setMenuBar(QWidget *widget)
bool close()
Q_DECL_DEPRECATED QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, const QgsDistanceArea &myDa, QWidget *parent=nullptr, bool showDialogButtons=true)
Create an attribute dialog for a given layer and feature.
virtual bool event(QEvent *e)
Type type() const
virtual void reject()
void restoreGeometry()
Restores the size and position from the last time this dialog box was used.
void hideButtonBox()
Hides the button box (Ok/Cancel) and enables auto-commit.
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.
void rejected()
bool save()
Save all the values from the editors to the layer.
void accepted()
void setHighlight(QgsHighlight *h)
setHighlight
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QString tr(const char *sourceText, const char *disambiguation, int n)
void setValue(const QString &key, const QVariant &value)
void show()
Show the dialog non-blocking. Reparents this dialog to be a child of the dialog form.
void setLayout(QLayout *layout)
bool restoreGeometry(const QByteArray &geometry)
This class is a menu that is populated automatically with the actions defined for a given layer...
Definition: qgsactionmenu.h:30
A class for highlight features on the map.
Definition: qgshighlight.h:36
void setDistanceArea(const QgsDistanceArea &distanceArea)
void setMargin(int margin)
void disconnectButtonBox()
Disconnects the button box (Ok/Cancel) from the accept/resetValues slots If this method is called...
void addWidget(QWidget *w)
virtual void accept()
General purpose distance and area calculator.
virtual bool event(QEvent *e) override
Intercept window activate/deactive events to show/hide the highlighted feature.
QString name() const
Get the display name of the layer.
QAction * addMenu(QMenu *menu)
void activateWindow()
QByteArray saveGeometry() const
void setWindowTitle(const QString &)
const QgsFeature * feature()
const QgsFeature & feature()
void accept() override
void show()
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QList< QAction * > actions() const
bool focusNextChild()
QObject * parent() const
Represents a vector layer which manages a vector based data sets.
T findChild(const QString &name) const