Skip to content

Commit

Permalink
vector layer updates
Browse files Browse the repository at this point in the history
- fix: retrieve only existing attributes from provider when editing and set
  added attributes to null
- introduce slider widget for attribute dialog
- include added attributes when editing from identify



git-svn-id: http://svn.osgeo.org/qgis/trunk@9182 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 27, 2008
1 parent eef7c97 commit 683dcea
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 24 deletions.
3 changes: 2 additions & 1 deletion python/core/qgsvectorlayer.sip
Expand Up @@ -11,7 +11,8 @@ public:
UniqueValuesEditable,
ValueMap,
Classification,
Range,
EditRange,
SliderRange
};

struct RangeData {
Expand Down
43 changes: 30 additions & 13 deletions src/app/qgsattributedialog.cpp
Expand Up @@ -32,6 +32,7 @@
#include <QFrame>
#include <QScrollArea>
#include <QCompleter>
#include <QSlider>
#include <QSpinBox>
#include <QDoubleSpinBox>

Expand All @@ -45,7 +46,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
if ( mpFeature == NULL || vl->dataProvider() == NULL )
return;

const QgsFieldMap &theFieldMap = vl->dataProvider()->fields();
const QgsFieldMap &theFieldMap = vl->pendingFields();

if ( theFieldMap.isEmpty() ) return;

Expand Down Expand Up @@ -161,21 +162,35 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}
break;

case QgsVectorLayer::Range:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::EditRange:
{
if ( myFieldType == QVariant::Int )
{
int min = vl->range( it.key() ).mMin.toInt();
int max = vl->range( it.key() ).mMax.toInt();
int step = vl->range( it.key() ).mStep.toInt();

QSpinBox *sb = new QSpinBox();
sb->setMinimum( min );
sb->setMaximum( max );
sb->setSingleStep( step );
sb->setValue( it.value().toInt() );
if ( editType == QgsVectorLayer::EditRange )
{
QSpinBox *sb = new QSpinBox();

myWidget = sb;
sb->setRange( min, max );
sb->setSingleStep( step );
sb->setValue( it.value().toInt() );

myWidget = sb;
}
else
{
QSlider *sl = new QSlider( Qt::Horizontal );

sl->setRange( min, max );
sl->setSingleStep( step );
sl->setValue( it.value().toInt() );

myWidget = sl;
}
break;
}
else if ( myFieldType == QVariant::Double )
Expand All @@ -185,16 +200,13 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
double step = vl->range( it.key() ).mStep.toDouble();
QDoubleSpinBox *dsb = new QDoubleSpinBox();

dsb->setMinimum( min );
dsb->setMaximum( max );
dsb->setRange( min, max );
dsb->setSingleStep( step );
dsb->setValue( it.value().toDouble() );

myWidget = dsb;

break;
}

}

// fall-through
Expand Down Expand Up @@ -292,13 +304,18 @@ void QgsAttributeDialog::accept()
}
}


QSpinBox *sb = dynamic_cast<QSpinBox *>( mpWidgets.value( myIndex ) );
if ( sb )
{
myFieldValue = QString::number( sb->value() );
}

QSlider *slider = dynamic_cast<QSlider *>( mpWidgets.value( myIndex ) );
if ( slider )
{
myFieldValue = QString::number( slider->value() );
}

QDoubleSpinBox *dsb = dynamic_cast<QDoubleSpinBox *>( mpWidgets.value( myIndex ) );
if ( dsb )
{
Expand Down
9 changes: 6 additions & 3 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -166,7 +166,8 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
cb->addItem( tr( "unique values (editable)" ), QgsVectorLayer::UniqueValuesEditable );
cb->addItem( tr( "value map" ), QgsVectorLayer::ValueMap );
cb->addItem( tr( "classification" ), QgsVectorLayer::Classification );
cb->addItem( tr( "range" ), QgsVectorLayer::Range );
cb->addItem( tr( "range (editable)" ), QgsVectorLayer::EditRange );
cb->addItem( tr( "range (slider)" ), QgsVectorLayer::SliderRange );
cb->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow );
cb->setCurrentIndex( layer->editType( idx ) );

Expand All @@ -188,7 +189,8 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )

tblAttributes->setItem( row, 7, new QTableWidgetItem( mapList.join( ";" ) ) );
}
else if ( layer->editType( idx ) == QgsVectorLayer::Range )
else if ( layer->editType( idx ) == QgsVectorLayer::EditRange ||
layer->editType( idx ) == QgsVectorLayer::SliderRange )
{
tblAttributes->setItem(
row, 7,
Expand Down Expand Up @@ -538,7 +540,8 @@ void QgsVectorLayerProperties::apply()
}
}
}
else if ( editType == QgsVectorLayer::Range )
else if ( editType == QgsVectorLayer::EditRange ||
editType == QgsVectorLayer::SliderRange )
{
QStringList values = tblAttributes->item( i, 7 )->text().split( ";" );

Expand Down
32 changes: 27 additions & 5 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1134,6 +1134,9 @@ void QgsVectorLayer::updateFeatureAttributes( QgsFeature &f )
for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); it++ )
f.changeAttribute( it.key(), it.value() );
}

for ( QgsAttributeList::const_iterator it = mFetchNullAttributes.begin(); it != mFetchNullAttributes.end(); it++ )
f.changeAttribute( *it, QVariant( QString::null ) );
}

void QgsVectorLayer::updateFeatureGeometry( QgsFeature &f )
Expand Down Expand Up @@ -1165,7 +1168,27 @@ void QgsVectorLayer::select( QgsAttributeList attributes, QgsRect rect, bool fet
//look in the normal features of the provider
if ( mFetchAttributes.size() > 0 )
{
mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
mFetchNullAttributes.clear();

if ( mEditable )
{
// fetch only available field from provider
QgsAttributeList provAttributes;
for ( QgsAttributeList::iterator it = mFetchAttributes.begin(); it != mFetchAttributes.end(); it++ )
{
if ( !mUpdatedFields.contains( *it ) )
continue;

if ( !mDeletedAttributeIds.contains( *it ) && !mAddedAttributeIds.contains( *it ) )
provAttributes << *it;
else
mFetchNullAttributes << *it;
}

mDataProvider->select( provAttributes, rect, fetchGeometries, useIntersect );
}
else
mDataProvider->select( mFetchAttributes, rect, fetchGeometries, useIntersect );
}
else
{
Expand Down Expand Up @@ -1957,6 +1980,7 @@ bool QgsVectorLayer::startEditing()
mEditable = true;

mUpdatedFields = mDataProvider->fields();

mMaxUpdatedIndex = -1;

for ( QgsFieldMap::const_iterator it = mUpdatedFields.begin(); it != mUpdatedFields.end(); it++ )
Expand Down Expand Up @@ -2049,7 +2073,7 @@ bool QgsVectorLayer::readXml( QDomNode & layer_node )
mValueMaps[ name ].insert( value.attribute( "key" ), value.attribute( "value" ) );
}
}
else if ( editType == Range )
else if ( editType == EditRange || editType == SliderRange )
{
QVariant min = editTypeElement.attribute( "min" );
QVariant max = editTypeElement.attribute( "max" );
Expand Down Expand Up @@ -2295,7 +2319,7 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node,
}
}
}
else if ( it.value() == Range )
else if ( it.value() == EditRange || it.value() == SliderRange )
{
if ( mRanges.contains( it.key() ) )
{
Expand Down Expand Up @@ -3266,8 +3290,6 @@ void QgsVectorLayer::drawFeature( QPainter* p,
if ( wkbType == QGis::WKBMultiPoint25D ) // ignore Z value
ptr += sizeof( double );

QgsDebugMsg( QString( "...WKBMultiPoint (%1, %2)" ).arg( x ).arg( y ) );

transformPoint( x, y, theMapToPixelTransform, ct );
//QPointF pt(x - (marker->width()/2), y - (marker->height()/2));
//QPointF pt(x/markerScaleFactor - (marker->width()/2), y/markerScaleFactor - (marker->height()/2));
Expand Down
6 changes: 4 additions & 2 deletions src/core/qgsvectorlayer.h
Expand Up @@ -66,7 +66,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
UniqueValuesEditable,
ValueMap,
Classification,
Range
EditRange,
SliderRange
};

struct RangeData
Expand Down Expand Up @@ -341,7 +342,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
void drawLabels( QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* cXf, const QgsCoordinateTransform* ct, double scale );

/** returns fields list which are not commited */
/** returns field list in the to-be-committed state */
const QgsFieldMap &pendingFields();

/** returns list of attributes */
Expand Down Expand Up @@ -608,6 +609,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
bool mFetching;
QgsRect mFetchRect;
QgsAttributeList mFetchAttributes;
QgsAttributeList mFetchNullAttributes;
bool mFetchGeometry;

QSet<int> mFetchConsidered;
Expand Down

0 comments on commit 683dcea

Please sign in to comment.