mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
vector layer updates
- 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
This commit is contained in:
parent
eef7c976d0
commit
683dcea781
@ -11,7 +11,8 @@ public:
|
||||
UniqueValuesEditable,
|
||||
ValueMap,
|
||||
Classification,
|
||||
Range,
|
||||
EditRange,
|
||||
SliderRange
|
||||
};
|
||||
|
||||
struct RangeData {
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <QFrame>
|
||||
#include <QScrollArea>
|
||||
#include <QCompleter>
|
||||
#include <QSlider>
|
||||
#include <QSpinBox>
|
||||
#include <QDoubleSpinBox>
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -161,7 +162,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
|
||||
}
|
||||
break;
|
||||
|
||||
case QgsVectorLayer::Range:
|
||||
case QgsVectorLayer::SliderRange:
|
||||
case QgsVectorLayer::EditRange:
|
||||
{
|
||||
if ( myFieldType == QVariant::Int )
|
||||
{
|
||||
@ -169,13 +171,26 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
|
||||
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 )
|
||||
@ -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
|
||||
@ -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 )
|
||||
{
|
||||
|
@ -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 ) );
|
||||
|
||||
@ -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,
|
||||
@ -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( ";" );
|
||||
|
||||
|
@ -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 )
|
||||
@ -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
|
||||
{
|
||||
@ -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++ )
|
||||
@ -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" );
|
||||
@ -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() ) )
|
||||
{
|
||||
@ -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));
|
||||
|
@ -66,7 +66,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
|
||||
UniqueValuesEditable,
|
||||
ValueMap,
|
||||
Classification,
|
||||
Range
|
||||
EditRange,
|
||||
SliderRange
|
||||
};
|
||||
|
||||
struct RangeData
|
||||
@ -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 */
|
||||
@ -608,6 +609,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
|
||||
bool mFetching;
|
||||
QgsRect mFetchRect;
|
||||
QgsAttributeList mFetchAttributes;
|
||||
QgsAttributeList mFetchNullAttributes;
|
||||
bool mFetchGeometry;
|
||||
|
||||
QSet<int> mFetchConsidered;
|
||||
|
Loading…
x
Reference in New Issue
Block a user