QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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( 0 )
31  , mOwnedFeature( featureOwner ? thepFeature : 0 )
32 {
34  context.setDistanceArea( myDa );
35 
36  init( vl, thepFeature, context, parent );
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( 0 )
45  , mOwnedFeature( featureOwner ? thepFeature : 0 )
46 {
47  init( vl, thepFeature, context, parent );
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 
90 void QgsAttributeDialog::show( bool autoDelete )
91 {
92  if ( autoDelete )
93  setAttribute( Qt::WA_DeleteOnClose );
94 
95  QDialog::show();
96  raise();
97  activateWindow();
98 }
99 
100 void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, const QgsAttributeEditorContext &context, QWidget* parent )
101 {
102  setWindowTitle( tr( "%1 - Feature Attributes" ).arg( layer->name() ) );
103  setLayout( new QGridLayout() );
104  layout()->setMargin( 0 );
105  mAttributeForm = new QgsAttributeForm( layer, *feature, context, parent );
106  mAttributeForm->disconnectButtonBox();
107  layout()->addWidget( mAttributeForm );
108  QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
109  connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
110  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
111  connect( layer, SIGNAL( layerDeleted() ), this, SLOT( close() ) );
112 
113  QgsActionMenu* menu = new QgsActionMenu( layer, &mAttributeForm->feature(), this );
114  if ( menu->actions().size() > 0 )
115  {
116  QMenuBar* menuBar = new QMenuBar( this );
117  menuBar->addMenu( menu );
118  layout()->setMenuBar( menuBar );
119  }
120  else
121  {
122  delete menu;
123  }
124 
125  restoreGeometry();
126  focusNextChild();
127 }