Skip to content

Commit

Permalink
cleanup and fix attribute widget configuration
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15691 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 10, 2011
1 parent 4d591b2 commit afa4214
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 142 deletions.
78 changes: 30 additions & 48 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -17,10 +17,9 @@
/* $Id$ */ /* $Id$ */


#include "qgsattributetypedialog.h" #include "qgsattributetypedialog.h"

#include "qgsattributetypeloaddialog.h" #include "qgsattributetypeloaddialog.h"

#include "qgsvectordataprovider.h" #include "qgsvectordataprovider.h"

#include "qgslogger.h" #include "qgslogger.h"


#include <QTableWidgetItem> #include <QTableWidgetItem>
Expand All @@ -33,19 +32,18 @@
#include <cfloat> #include <cfloat>


QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl ) QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl )
: QDialog(), : QDialog()
mLayer( vl ) , mLayer( vl )
{ {
setupUi( this ); setupUi( this );
tableWidget->insertRow( 0 ); tableWidget->insertRow( 0 );
connect( selectionComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setStackPage( int ) ) ); connect( selectionComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( setStackPage( int ) ) );
connect( removeSelectedButton, SIGNAL( pressed( ) ), this, SLOT( removeSelectedButtonPushed( ) ) ); connect( removeSelectedButton, SIGNAL( clicked() ), this, SLOT( removeSelectedButtonPushed() ) );
connect( loadFromLayerButton, SIGNAL( pressed( ) ), this, SLOT( loadFromLayerButtonPushed( ) ) ); connect( loadFromLayerButton, SIGNAL( clicked() ), this, SLOT( loadFromLayerButtonPushed() ) );
connect( loadFromCSVButton, SIGNAL( pressed( ) ), this, SLOT( loadFromCSVButtonPushed( ) ) ); connect( loadFromCSVButton, SIGNAL( clicked() ), this, SLOT( loadFromCSVButtonPushed() ) );
connect( tableWidget, SIGNAL( cellChanged( int, int ) ), this, SLOT( vCellChanged( int, int ) ) ); connect( tableWidget, SIGNAL( cellChanged( int, int ) ), this, SLOT( vCellChanged( int, int ) ) );
} }



QgsAttributeTypeDialog::~QgsAttributeTypeDialog() QgsAttributeTypeDialog::~QgsAttributeTypeDialog()
{ {


Expand Down Expand Up @@ -211,6 +209,10 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
{ {
switch ( editType ) switch ( editType )
{ {
case QgsVectorLayer::LineEdit:
setPage( 0 );
break;

case QgsVectorLayer::Classification: case QgsVectorLayer::Classification:
setPage( 1 ); setPage( 1 );
break; break;
Expand Down Expand Up @@ -252,21 +254,14 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy


case QgsVectorLayer::TextEdit: case QgsVectorLayer::TextEdit:
setPage( 10 ); setPage( 10 );
break;


case QgsVectorLayer::Calendar: case QgsVectorLayer::Calendar:
setPage( 11 ); setPage( 11 );

case QgsVectorLayer::LineEdit:
setPage( 0 );
break; break;
} }
} }


void QgsAttributeTypeDialog::setPageForIndex( int index )
{
setPageForEditType( mLayer->editType( index ) );
}

void QgsAttributeTypeDialog::setValueMap( QMap<QString, QVariant> valueMap ) void QgsAttributeTypeDialog::setValueMap( QMap<QString, QVariant> valueMap )
{ {
mValueMap = valueMap; mValueMap = valueMap;
Expand All @@ -277,19 +272,10 @@ void QgsAttributeTypeDialog::setRange( QgsVectorLayer::RangeData range )
mRangeData = range; mRangeData = range;
} }


void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt ) void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editType )
{ {
mIndex = index; mIndex = index;
//need to set index for combobox //need to set index for combobox
QgsVectorLayer::EditType editType;
if ( editTypeInt > -1 )
{
editType = QgsVectorLayer::EditType( editTypeInt );
}
else
{
editType = mLayer->editType( index );
}


setWindowTitle( defaultWindowTitle() + " \"" + mLayer->pendingFields()[index].name() + "\"" ); setWindowTitle( defaultWindowTitle() + " \"" + mLayer->pendingFields()[index].name() + "\"" );
QgsAttributeList attributeList = QgsAttributeList(); QgsAttributeList attributeList = QgsAttributeList();
Expand Down Expand Up @@ -346,33 +332,20 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
} }
valuesLabel->setText( text ); valuesLabel->setText( text );


//setPageForIndex( index );
setPageForEditType( editType ); setPageForEditType( editType );


switch ( editType ) switch ( editType )
{ {
case QgsVectorLayer::ValueMap: case QgsVectorLayer::ValueMap:
{ {

tableWidget->clearContents(); tableWidget->clearContents();
for ( int i = tableWidget->rowCount() - 1; i > 0; i-- ) for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
{ {
tableWidget->removeRow( i ); tableWidget->removeRow( i );
} }


// if some value map already present use it
QMap<QString, QVariant> map;
if ( !mValueMap.empty() )
{
map = mValueMap;
}
else
{
map = mLayer->valueMap( index );
}

int row = 0; int row = 0;
for ( QMap<QString, QVariant>::iterator mit = map.begin(); mit != map.end(); mit++, row++ ) for ( QMap<QString, QVariant>::iterator mit = mValueMap.begin(); mit != mValueMap.end(); mit++, row++ )
{ {
tableWidget->insertRow( row ); tableWidget->insertRow( row );
if ( mit.value().isNull() ) if ( mit.value().isNull() )
Expand All @@ -395,15 +368,15 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
{ {
if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int ) if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int )
{ {
minimumSpinBox->setValue( mLayer->range( index ).mMin.toInt() ); minimumSpinBox->setValue( mRangeData.mMin.toInt() );
maximumSpinBox->setValue( mLayer->range( index ).mMax.toInt() ); maximumSpinBox->setValue( mRangeData.mMax.toInt() );
stepSpinBox->setValue( mLayer->range( index ).mStep.toInt() ); stepSpinBox->setValue( mRangeData.mStep.toInt() );
} }
else if ( mLayer->pendingFields()[mIndex].type() == QVariant::Double ) else if ( mLayer->pendingFields()[mIndex].type() == QVariant::Double )
{ {
minimumDoubleSpinBox->setValue( mLayer->range( index ).mMin.toDouble() ); minimumDoubleSpinBox->setValue( mRangeData.mMin.toDouble() );
maximumDoubleSpinBox->setValue( mLayer->range( index ).mMax.toDouble() ); maximumDoubleSpinBox->setValue( mRangeData.mMax.toDouble() );
stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() ); stepDoubleSpinBox->setValue( mRangeData.mStep.toDouble() );
} }
if ( editType == QgsVectorLayer::EditRange ) if ( editType == QgsVectorLayer::EditRange )
{ {
Expand All @@ -424,7 +397,16 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
editableUniqueValues->setChecked( editType == QgsVectorLayer::UniqueValuesEditable ); editableUniqueValues->setChecked( editType == QgsVectorLayer::UniqueValuesEditable );
break; break;


default: case QgsVectorLayer::LineEdit:
case QgsVectorLayer::UniqueValues:
case QgsVectorLayer::Classification:
case QgsVectorLayer::CheckBox:
case QgsVectorLayer::FileName:
case QgsVectorLayer::Enumeration:
case QgsVectorLayer::Immutable:
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::Calendar:
break; break;
} }
} }
Expand Down
8 changes: 1 addition & 7 deletions src/app/qgsattributetypedialog.h
Expand Up @@ -45,7 +45,7 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog
* @param index of page to be selected * @param index of page to be selected
* @param editTypeInt type of edit type which was selected before save * @param editTypeInt type of edit type which was selected before save
*/ */
void setIndex( int index, int editTypeInt = -1 ); void setIndex( int index, QgsVectorLayer::EditType editType );


/** /**
* Setting page which is to be selected * Setting page which is to be selected
Expand Down Expand Up @@ -128,12 +128,6 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog


QString defaultWindowTitle(); QString defaultWindowTitle();


/**
* Function to set page index
* @param index index of page to be changed
*/
void setPageForIndex( int index );

/** /**
* Function to set page according to edit type * Function to set page according to edit type
* @param editType edit type to set page * @param editType edit type to set page
Expand Down
7 changes: 4 additions & 3 deletions src/app/qgsattributetypeloaddialog.cpp
Expand Up @@ -71,10 +71,11 @@ void QgsAttributeTypeLoadDialog::previewButtonPushed()
void QgsAttributeTypeLoadDialog::fillLayerList() void QgsAttributeTypeLoadDialog::fillLayerList()
{ {
layerComboBox->clear(); layerComboBox->clear();
QMap<QString, QgsMapLayer*>::iterator layer_it = QgsMapLayerRegistry::instance()->mapLayers().begin(); foreach( QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() )
for ( ; layer_it != QgsMapLayerRegistry::instance()->mapLayers().end(); layer_it++ )
{ {
layerComboBox->addItem( layer_it.value()->name(), layer_it.key() ); QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( l );
if ( vl )
layerComboBox->addItem( vl->name(), vl->id() );
} }
} }


Expand Down
110 changes: 55 additions & 55 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -215,7 +215,7 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )


QPushButton *pb = new QPushButton( editTypeButtonText( layer->editType( idx ) ) ); QPushButton *pb = new QPushButton( editTypeButtonText( layer->editType( idx ) ) );
tblAttributes->setCellWidget( row, attrEditTypeCol, pb ); tblAttributes->setCellWidget( row, attrEditTypeCol, pb );
connect( pb, SIGNAL( pressed() ), this, SLOT( attributeTypeDialog( ) ) ); connect( pb, SIGNAL( clicked() ), this, SLOT( attributeTypeDialog() ) );
mButtonMap.insert( idx, pb ); mButtonMap.insert( idx, pb );


//set the alias for the attribute //set the alias for the attribute
Expand All @@ -231,7 +231,7 @@ QgsVectorLayerProperties::~QgsVectorLayerProperties()
settings.setValue( "/Windows/VectorLayerProperties/row", tabWidget->currentIndex() ); settings.setValue( "/Windows/VectorLayerProperties/row", tabWidget->currentIndex() );
} }


void QgsVectorLayerProperties::attributeTypeDialog( ) void QgsVectorLayerProperties::attributeTypeDialog()
{ {
QPushButton *pb = qobject_cast<QPushButton *>( sender() ); QPushButton *pb = qobject_cast<QPushButton *>( sender() );
if ( !pb ) if ( !pb )
Expand All @@ -243,37 +243,13 @@ void QgsVectorLayerProperties::attributeTypeDialog( )


QgsAttributeTypeDialog attributeTypeDialog( layer ); QgsAttributeTypeDialog attributeTypeDialog( layer );


if ( mValueMaps.contains( index ) ) attributeTypeDialog.setValueMap( mValueMaps.value( index, layer->valueMap( index ) ) );
{ attributeTypeDialog.setRange( mRanges.value( index, layer->range( index ) ) );
attributeTypeDialog.setValueMap( mValueMaps[index] );
}
else
{
attributeTypeDialog.setValueMap( QMap<QString, QVariant>() );
}


if ( mRanges.contains( index ) ) QPair<QString, QString> checkStates = mCheckedStates.value( index, layer->checkedState( index ) );
{ attributeTypeDialog.setCheckedState( checkStates.first, checkStates.second );
attributeTypeDialog.setRange( mRanges[index] );
}
else
{
attributeTypeDialog.setRange( QgsVectorLayer::RangeData( 0, 5, 1 ) );
}


if ( mEditTypeMap.contains( index ) ) attributeTypeDialog.setIndex( index, mEditTypeMap.value( index, layer->editType( index ) ) );
{
attributeTypeDialog.setIndex( index, mEditTypeMap[index] );
}
else
{
attributeTypeDialog.setIndex( index );
}

if ( mCheckedStates.contains( index ) )
{
attributeTypeDialog.setCheckedState( mCheckedStates[index].first, mCheckedStates[index].second );
}


if ( !attributeTypeDialog.exec() ) if ( !attributeTypeDialog.exec() )
return; return;
Expand All @@ -295,7 +271,17 @@ void QgsVectorLayerProperties::attributeTypeDialog( )
break; break;
case QgsVectorLayer::CheckBox: case QgsVectorLayer::CheckBox:
mCheckedStates.insert( index, attributeTypeDialog.checkedState() ); mCheckedStates.insert( index, attributeTypeDialog.checkedState() );
default: break;
case QgsVectorLayer::LineEdit:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UniqueValues:
case QgsVectorLayer::UniqueValuesEditable:
case QgsVectorLayer::Classification:
case QgsVectorLayer::FileName:
case QgsVectorLayer::Enumeration:
case QgsVectorLayer::Immutable:
case QgsVectorLayer::Hidden:
case QgsVectorLayer::Calendar:
break; break;
} }


Expand Down Expand Up @@ -622,30 +608,44 @@ void QgsVectorLayerProperties::apply()
QgsVectorLayer::EditType editType = editTypeFromButtonText( pb->text() ); QgsVectorLayer::EditType editType = editTypeFromButtonText( pb->text() );
layer->setEditType( idx, editType ); layer->setEditType( idx, editType );


if ( editType == QgsVectorLayer::ValueMap ) switch ( editType )
{
if ( mValueMaps.contains( idx ) )
{
QMap<QString, QVariant> &map = layer->valueMap( idx );
map.clear();
map = mValueMaps[idx];
}
}
else if ( editType == QgsVectorLayer::EditRange ||
editType == QgsVectorLayer::SliderRange ||
editType == QgsVectorLayer::DialRange )
{
if ( mRanges.contains( idx ) )
{
layer->range( idx ) = mRanges[idx];
}
}
else if ( editType == QgsVectorLayer::CheckBox )
{ {
if ( mCheckedStates.contains( idx ) ) case QgsVectorLayer::ValueMap:
{ if ( mValueMaps.contains( idx ) )
layer->setCheckedState( idx, mCheckedStates[idx].first, mCheckedStates[idx].second ); {
} QMap<QString, QVariant> &map = layer->valueMap( idx );
map.clear();
map = mValueMaps[idx];
}
break;

case QgsVectorLayer::EditRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::DialRange:
if ( mRanges.contains( idx ) )
{
layer->range( idx ) = mRanges[idx];
}
break;

case QgsVectorLayer::CheckBox:
if ( mCheckedStates.contains( idx ) )
{
layer->setCheckedState( idx, mCheckedStates[idx].first, mCheckedStates[idx].second );
}
break;

case QgsVectorLayer::LineEdit:
case QgsVectorLayer::UniqueValues:
case QgsVectorLayer::UniqueValuesEditable:
case QgsVectorLayer::Classification:
case QgsVectorLayer::FileName:
case QgsVectorLayer::Enumeration:
case QgsVectorLayer::Immutable:
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::Calendar:
break;
} }
} }


Expand Down

0 comments on commit afa4214

Please sign in to comment.