QGIS API Documentation  2.5.0-Master
 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 
23 #include <QSettings>
24 #include <QGridLayout>
25 
26 
27 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QgsDistanceArea myDa, QWidget* parent, bool showDialogButtons )
28  : QDialog( parent )
29  , mHighlight( 0 )
30 {
32  context.setDistanceArea( myDa );
33  init( vl, thepFeature, context, parent );
34 
35  if ( !showDialogButtons )
37 
38  if ( featureOwner )
39  delete thepFeature;
40 }
41 
42 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QWidget* parent, bool showDialogButtons, QgsAttributeEditorContext context )
43  : QDialog( parent )
44  , mHighlight( 0 )
45 {
46  init( vl, thepFeature, context, parent );
47 
48  if ( !showDialogButtons )
50 
51  if ( featureOwner )
52  delete thepFeature;
53 }
54 
56 {
57  if ( mHighlight )
58  {
59  mHighlight->hide();
60  delete mHighlight;
61  }
62 
63  saveGeometry();
64 }
65 
67 {
68  QSettings().setValue( mSettingsPath + "geometry", QDialog::saveGeometry() );
69 }
70 
72 {
73  QDialog::restoreGeometry( QSettings().value( mSettingsPath + "geometry" ).toByteArray() );
74 }
75 
77 {
78  delete mHighlight;
79 
80  mHighlight = h;
81 }
82 
84 {
86  QDialog::accept();
87 }
88 
89 void QgsAttributeDialog::show( bool autoDelete )
90 {
91  if ( autoDelete )
92  setAttribute( Qt::WA_DeleteOnClose );
93 
94  QDialog::show();
95  raise();
96  activateWindow();
97 }
98 
99 void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, QgsAttributeEditorContext& context, QWidget* parent )
100 {
101  setWindowTitle( tr( "Feature Attributes" ) );
102  setLayout( new QGridLayout() );
103  layout()->setMargin( 0 );
104  mAttributeForm = new QgsAttributeForm( layer, *feature, context, parent );
106  layout()->addWidget( mAttributeForm );
107  QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
108  connect( buttonBox, SIGNAL( rejected() ), this, SLOT( reject() ) );
109  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
110  restoreGeometry();
111  focusNextChild();
112 }
void show(bool autoDelete=true)
Show the dialog non-blocking.
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.
QgsAttributeForm * mAttributeForm
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.
QgsHighlight * mHighlight
bool save()
Save all the values from the editors to the layer.
void setHighlight(QgsHighlight *h)
setHighlight
QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QgsDistanceArea myDa, QWidget *parent=0, bool showDialogButtons=true)
Create an attribute dialog for a given layer and feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
A class for highlight features on the map.
Definition: qgshighlight.h:36
void setDistanceArea(const QgsDistanceArea &distanceArea)
void disconnectButtonBox()
Disconnects the button box (Ok/Cancel) from the accept/resetValues slots If this method is called...
General purpose distance and area calculator.
void init(QgsVectorLayer *layer, QgsFeature *feature, QgsAttributeEditorContext &context, QWidget *parent)
Represents a vector layer which manages a vector based data sets.
#define tr(sourceText)