Skip to content

Commit

Permalink
moved include of QgsAttributeDialog out of QgsFeature such that it is…
Browse files Browse the repository at this point in the history
… a gui independent class now

git-svn-id: http://svn.osgeo.org/qgis/trunk@4812 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 7, 2006
1 parent ff653af commit 2b6e03d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 34 deletions.
23 changes: 21 additions & 2 deletions src/gui/qgsattributedialog.cpp
Expand Up @@ -16,16 +16,17 @@
***************************************************************************/
/* $Id$ */
#include "qgsattributedialog.h"
#include "qgsfeature.h"
#include <QTableWidgetItem>

QgsAttributeDialog::QgsAttributeDialog(std::vector<QgsFeatureAttribute>* attributes)
QgsAttributeDialog::QgsAttributeDialog(const std::vector<QgsFeatureAttribute>* attributes)
: QDialog()
{
setupUi(this);
mTable->setRowCount(attributes->size());

int index=0;
for(std::vector<QgsFeatureAttribute>::iterator it=attributes->begin();it!=attributes->end();++it)
for(std::vector<QgsFeatureAttribute>::const_iterator it=attributes->begin();it!=attributes->end();++it)
{
QTableWidgetItem * myFieldItem = new QTableWidgetItem((*it).fieldName());
mTable->setItem(index, 0, myFieldItem);
Expand All @@ -44,3 +45,21 @@ QString QgsAttributeDialog::value(int row)
{
return mTable->item(row,1)->text();
}

bool QgsAttributeDialog::queryAttributes(QgsFeature& f)
{
const std::vector<QgsFeatureAttribute> featureAttributes = f.attributeMap();
QgsAttributeDialog attdialog(&featureAttributes);
if(attdialog.exec()==QDialog::Accepted)
{
for(int i=0;i<featureAttributes.size();++i)
{
f.changeAttributeValue(featureAttributes[i].fieldName(), attdialog.value(i));
}
return true;
}
else
{
return false;
}
}
7 changes: 6 additions & 1 deletion src/gui/qgsattributedialog.h
Expand Up @@ -24,15 +24,20 @@
#include <vector>

class QDialog;
class QgsFeature;

class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
{
Q_OBJECT
public:
QgsAttributeDialog(std::vector<QgsFeatureAttribute>* attributes);
QgsAttributeDialog(const std::vector<QgsFeatureAttribute>* attributes);
~QgsAttributeDialog();
/**Returns the field value of a row*/
QString value(int row);
/**Opens an attribute dialog and queries the attributes for a given feature. The
attribute values are set to the feature if the dialog is accepted.
Returns true if accepted and false if canceled*/
static bool queryAttributes(QgsFeature& f);
};

#endif
19 changes: 0 additions & 19 deletions src/gui/qgsfeature.cpp
Expand Up @@ -15,7 +15,6 @@ email : sherman at mrcc.com
/* $Id$ */

#include "qgsfeature.h"
#include "qgsattributedialog.h"
#include "qgsrect.h"
#include <iostream>
#include <cfloat>
Expand Down Expand Up @@ -812,24 +811,6 @@ void QgsFeature::resetDirty()
mDirty = FALSE;
}


bool QgsFeature::attributeDialog()
{
QgsAttributeDialog attdialog(&attributes);
if(attdialog.exec()==QDialog::Accepted)
{
for(int i=0;i<attributes.size();++i)
{
attributes[i].setFieldValue(attdialog.value(i));
}
return true;
}
else
{
return false;
}
}

// bool QgsFeature::intersects(QgsRect* r) const
// {
// bool returnval=false;
Expand Down
4 changes: 0 additions & 4 deletions src/gui/qgsfeature.h
Expand Up @@ -205,10 +205,6 @@ class QgsFeature {
* to the given coordinates
*/
/* bool vertexAt(double &x, double &y, int atVertex = 0, int atRing = 0, int atItem = 0) const;*/

/**Shows a popup dialog to change attribute values
@return true if dialog is accepted, false if rejected*/
bool attributeDialog();

// /**Test for intersection with a rectangle (uses GEOS)*/
// bool intersects(QgsRect* r) const;
Expand Down
17 changes: 9 additions & 8 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -2052,10 +2052,10 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
}

//show the dialog to enter attribute values
if(f->attributeDialog())
{
vlayer->addFeature(f);
}
if(QgsAttributeDialog::queryAttributes(*f))
{
vlayer->addFeature(f);
}
refresh();
}
}
Expand Down Expand Up @@ -2247,10 +2247,11 @@ void QgsMapCanvas::mouseReleaseEvent(QMouseEvent * e)
f->addAttribute((*it).name(),vlayer->getDefaultValue(it->name(), f));
}

if(f->attributeDialog())
{
vlayer->addFeature(f);
}
//show the dialog to enter attribute values
if(QgsAttributeDialog::queryAttributes(*f))
{
vlayer->addFeature(f);
}

// delete the elements of mCaptureList
mCaptureList.clear();
Expand Down

0 comments on commit 2b6e03d

Please sign in to comment.