QGIS API Documentation  2.4.0-Chugiak
 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 : [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 
23 #include <QSettings>
24 #include <QGridLayout>
25 
26 
27 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QgsDistanceArea myDa, QWidget* parent, bool showDialogButtons )
28  : QObject( 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  : QObject( 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  delete mDialog;
64 }
65 
67 {
68  if ( mDialog )
69  {
70  QSettings settings;
71  settings.setValue( mSettingsPath + "geometry", mDialog->saveGeometry() );
72  }
73 }
74 
76 {
77  if ( mDialog )
78  {
79  QSettings settings;
80  mDialog->restoreGeometry( settings.value( mSettingsPath + "geometry" ).toByteArray() );
81  }
82 }
83 
85 {
86  delete mHighlight;
87 
88  mHighlight = h;
89 }
90 
92 {
94 }
95 
97 {
98  if ( mDialog )
99  {
100  return mDialog->exec();
101  }
102  else
103  {
104  QgsDebugMsg( "No dialog" );
105  return QDialog::Accepted;
106  }
107 }
108 
110 {
111  if ( mDialog )
112  {
113  mDialog->setAttribute( Qt::WA_DeleteOnClose );
114  mDialog->show();
115  mDialog->raise();
116  mDialog->activateWindow();
117  mDialog->installEventFilter( this );
118  setParent( mDialog );
119  }
120 }
121 
122 bool QgsAttributeDialog::eventFilter( QObject* obj, QEvent* e )
123 {
124  if ( mHighlight && obj == mDialog )
125  {
126  switch ( e->type() )
127  {
128  case QEvent::WindowActivate:
129  mHighlight->show();
130  break;
131 
132  case QEvent::WindowDeactivate:
133  mHighlight->hide();
134  break;
135 
136  default:
137  break;
138  }
139  }
140 
141  return false;
142 }
143 
145 {
146  Q_UNUSED( result )
147  saveGeometry();
148 }
149 
150 void QgsAttributeDialog::init( QgsVectorLayer* layer, QgsFeature* feature, QgsAttributeEditorContext& context, QWidget* parent )
151 {
152  mDialog = new QDialog( parent );
153  mDialog->setWindowTitle( tr( "Feature Attributes" ) );
154  mDialog->setLayout( new QGridLayout() );
155  mDialog->layout()->setMargin( 0 );
156  mAttributeForm = new QgsAttributeForm( layer, *feature, context, parent );
157  mDialog->layout()->addWidget( mAttributeForm );
158  QDialogButtonBox* buttonBox = mAttributeForm->findChild<QDialogButtonBox*>();
159  connect( buttonBox, SIGNAL( rejected() ), mDialog, SLOT( reject() ) );
160  connect( buttonBox, SIGNAL( accepted() ), mDialog, SLOT( accept() ) );
161  connect( mDialog, SIGNAL( finished( int ) ), this, SLOT( onDialogFinished( int ) ) );
162  restoreGeometry();
163 }
int exec()
Show the dialog and block the application until the dialog is closed. Ownership of this object is not...
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
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
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
void show()
Show the dialog non-blocking.
A class for highlight features on the map.
Definition: qgshighlight.h:36
void setDistanceArea(const QgsDistanceArea &distanceArea)
QPointer< QDialog > mDialog
General purpose distance and area calculator.
void onDialogFinished(int result)
bool eventFilter(QObject *obj, QEvent *e)
void init(QgsVectorLayer *layer, QgsFeature *feature, QgsAttributeEditorContext &context, QWidget *parent)
Represents a vector layer which manages a vector based data sets.
#define tr(sourceText)