Navigation Menu

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/qgis@15691 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 10, 2011
1 parent 191ded1 commit 534d1e3
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$ */

#include "qgsattributetypedialog.h"

#include "qgsattributetypeloaddialog.h"

#include "qgsvectordataprovider.h"

#include "qgslogger.h"

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

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


QgsAttributeTypeDialog::~QgsAttributeTypeDialog()
{

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

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

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

case QgsVectorLayer::Calendar:
setPage( 11 );

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

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

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

void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editType )
{
mIndex = index;
//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() + "\"" );
QgsAttributeList attributeList = QgsAttributeList();
Expand Down Expand Up @@ -346,33 +332,20 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
}
valuesLabel->setText( text );

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

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

tableWidget->clearContents();
for ( int i = tableWidget->rowCount() - 1; i > 0; 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;
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 );
if ( mit.value().isNull() )
Expand All @@ -395,15 +368,15 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
{
if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int )
{
minimumSpinBox->setValue( mLayer->range( index ).mMin.toInt() );
maximumSpinBox->setValue( mLayer->range( index ).mMax.toInt() );
stepSpinBox->setValue( mLayer->range( index ).mStep.toInt() );
minimumSpinBox->setValue( mRangeData.mMin.toInt() );
maximumSpinBox->setValue( mRangeData.mMax.toInt() );
stepSpinBox->setValue( mRangeData.mStep.toInt() );
}
else if ( mLayer->pendingFields()[mIndex].type() == QVariant::Double )
{
minimumDoubleSpinBox->setValue( mLayer->range( index ).mMin.toDouble() );
maximumDoubleSpinBox->setValue( mLayer->range( index ).mMax.toDouble() );
stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() );
minimumDoubleSpinBox->setValue( mRangeData.mMin.toDouble() );
maximumDoubleSpinBox->setValue( mRangeData.mMax.toDouble() );
stepDoubleSpinBox->setValue( mRangeData.mStep.toDouble() );
}
if ( editType == QgsVectorLayer::EditRange )
{
Expand All @@ -424,7 +397,16 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
editableUniqueValues->setChecked( editType == QgsVectorLayer::UniqueValuesEditable );
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;
}
}
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 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
Expand Down Expand Up @@ -128,12 +128,6 @@ class QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttributeTypeDialog

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
* @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()
{
layerComboBox->clear();
QMap<QString, QgsMapLayer*>::iterator layer_it = QgsMapLayerRegistry::instance()->mapLayers().begin();
for ( ; layer_it != QgsMapLayerRegistry::instance()->mapLayers().end(); layer_it++ )
foreach( QgsMapLayer *l, QgsMapLayerRegistry::instance()->mapLayers() )
{
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 ) ) );
tblAttributes->setCellWidget( row, attrEditTypeCol, pb );
connect( pb, SIGNAL( pressed() ), this, SLOT( attributeTypeDialog( ) ) );
connect( pb, SIGNAL( clicked() ), this, SLOT( attributeTypeDialog() ) );
mButtonMap.insert( idx, pb );

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

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

QgsAttributeTypeDialog attributeTypeDialog( layer );

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

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

if ( mEditTypeMap.contains( index ) )
{
attributeTypeDialog.setIndex( index, mEditTypeMap[index] );
}
else
{
attributeTypeDialog.setIndex( index );
}

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

if ( !attributeTypeDialog.exec() )
return;
Expand All @@ -295,7 +271,17 @@ void QgsVectorLayerProperties::attributeTypeDialog( )
break;
case QgsVectorLayer::CheckBox:
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;
}

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

if ( editType == QgsVectorLayer::ValueMap )
{
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 )
switch ( editType )
{
if ( mCheckedStates.contains( idx ) )
{
layer->setCheckedState( idx, mCheckedStates[idx].first, mCheckedStates[idx].second );
}
case QgsVectorLayer::ValueMap:
if ( mValueMaps.contains( idx ) )
{
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 534d1e3

Please sign in to comment.