Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add widget support for dials and calendar
git-svn-id: http://svn.osgeo.org/qgis/trunk@13252 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 5, 2010
1 parent 5602a33 commit f82574f
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 50 deletions.
3 changes: 2 additions & 1 deletion src/app/attributetable/qgsattributetabledelegate.cpp
Expand Up @@ -69,7 +69,8 @@ QWidget *QgsAttributeTableDelegate::createEditor(
QgsAttributeTableView *tv = dynamic_cast<QgsAttributeTableView *>( parent->parentWidget() );
w->setMinimumWidth( tv->columnWidth( index.column() ) );

if ( vl->editType( fieldIdx( index ) ) == QgsVectorLayer::FileName )
if ( vl->editType( fieldIdx( index ) ) == QgsVectorLayer::FileName ||
vl->editType( fieldIdx( index ) ) == QgsVectorLayer::Calendar )
{
QLineEdit *le = w->findChild<QLineEdit*>();
le->adjustSize();
Expand Down
53 changes: 37 additions & 16 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -217,6 +217,7 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy

case QgsVectorLayer::EditRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::DialRange:
setPage( 2 );
break;

Expand Down Expand Up @@ -252,6 +253,9 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
case QgsVectorLayer::TextEdit:
setPage( 10 );

case QgsVectorLayer::Calendar:
setPage( 11 );

case QgsVectorLayer::LineEdit:
setPage( 0 );
break;
Expand Down Expand Up @@ -297,7 +301,8 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
//calculate min and max for range for this field
if ( mLayer->pendingFields()[index].type() == QVariant::Int )
{
sliderRadioButton->setDisabled( false );
rangeWidget->clear();
rangeWidget->addItems( QStringList() << tr( "Editable" ) << tr( "Slider" ) << tr( "Dial" ) );
int min = INT_MIN;
int max = INT_MAX;
while ( mLayer->nextFeature( f ) )
Expand All @@ -319,8 +324,8 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
double dMin = -DBL_MAX;
double dMax = DBL_MAX;

sliderRadioButton->setDisabled( true );
editableRadioButton->setChecked( true );
rangeWidget->clear();
rangeWidget->addItems( QStringList() << tr( "Editable" ) << tr( "Slider" ) );
while ( mLayer->nextFeature( f ) )
{
QVariant val = f.attributeMap()[index];
Expand Down Expand Up @@ -386,6 +391,7 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )

case QgsVectorLayer::EditRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::DialRange:
{
if ( mLayer->pendingFields()[mIndex].type() != QVariant::Int )
{
Expand All @@ -400,9 +406,17 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )
stepDoubleSpinBox->setValue( mLayer->range( index ).mStep.toDouble() );
}
if ( editType == QgsVectorLayer::EditRange )
editableRadioButton->setChecked( true );
else //slider range
sliderRadioButton->setChecked( true );
{
rangeWidget->setCurrentIndex( 0 );
}
else if ( editType == QgsVectorLayer::SliderRange )
{
rangeWidget->setCurrentIndex( 1 );
}
else
{
rangeWidget->setCurrentIndex( 2 );
}
}
break;

Expand All @@ -418,13 +432,13 @@ void QgsAttributeTypeDialog::setIndex( int index, int editTypeInt )

void QgsAttributeTypeDialog::setPage( int index )
{
this->selectionComboBox->setCurrentIndex( index );
selectionComboBox->setCurrentIndex( index );
setStackPage( index );
}

void QgsAttributeTypeDialog::setStackPage( int index )
{
this->stackedWidget->setCurrentIndex( index );
stackedWidget->setCurrentIndex( index );

bool okDisabled = false;
if ( index == 2 )
Expand All @@ -436,15 +450,15 @@ void QgsAttributeTypeDialog::setStackPage( int index )
}
else if ( mLayer->pendingFields()[mIndex].type() != QVariant::Double )
{
this->rangeStackedWidget->setCurrentIndex( 0 );
rangeStackedWidget->setCurrentIndex( 0 );
//load data
minimumSpinBox->setValue( mRangeData.mMin.toInt() );
maximumSpinBox->setValue( mRangeData.mMax.toInt() );
stepSpinBox->setValue( mRangeData.mStep.toInt() );
}
else
{
this->rangeStackedWidget->setCurrentIndex( 1 );
rangeStackedWidget->setCurrentIndex( 1 );
//load data
minimumDoubleSpinBox->setValue( mRangeData.mMin.toDouble() );
maximumDoubleSpinBox->setValue( mRangeData.mMax.toDouble() );
Expand Down Expand Up @@ -497,13 +511,17 @@ void QgsAttributeTypeDialog::accept()
stepDoubleSpinBox->value() );
}
//select correct one
if ( editableRadioButton->isChecked() )
{
mEditType = QgsVectorLayer::EditRange;
}
else
switch ( rangeWidget->currentIndex() )
{
mEditType = QgsVectorLayer::SliderRange;
case 0:
mEditType = QgsVectorLayer::EditRange;
break;
case 1:
mEditType = QgsVectorLayer::SliderRange;
break;
case 2:
mEditType = QgsVectorLayer::DialRange;
break;
}
break;
case 3:
Expand Down Expand Up @@ -550,6 +568,9 @@ void QgsAttributeTypeDialog::accept()
case 10:
mEditType = QgsVectorLayer::TextEdit;
break;
case 11:
mEditType = QgsVectorLayer::Calendar;
break;
}

QDialog::accept();
Expand Down
7 changes: 5 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -271,6 +271,7 @@ void QgsVectorLayerProperties::attributeTypeDialog( )
break;
case QgsVectorLayer::EditRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::DialRange:
mRanges.insert( index, attributeTypeDialog.rangeData() );
break;
case QgsVectorLayer::CheckBox:
Expand Down Expand Up @@ -532,12 +533,14 @@ void QgsVectorLayerProperties::setupEditTypes()
editTypeMap.insert( QgsVectorLayer::ValueMap, tr( "Value map" ) );
editTypeMap.insert( QgsVectorLayer::EditRange, tr( "Edit range" ) );
editTypeMap.insert( QgsVectorLayer::SliderRange, tr( "Slider range" ) );
editTypeMap.insert( QgsVectorLayer::DialRange, tr( "Dial range" ) );
editTypeMap.insert( QgsVectorLayer::FileName, tr( "File name" ) );
editTypeMap.insert( QgsVectorLayer::Enumeration, tr( "Enumeration" ) );
editTypeMap.insert( QgsVectorLayer::Immutable, tr( "Immutable" ) );
editTypeMap.insert( QgsVectorLayer::Hidden, tr( "Hidden" ) );
editTypeMap.insert( QgsVectorLayer::CheckBox, tr( "Checkbox" ) );
editTypeMap.insert( QgsVectorLayer::TextEdit, tr( "Text edit" ) );
editTypeMap.insert( QgsVectorLayer::Calendar, tr( "Calendar" ) );
}

QString QgsVectorLayerProperties::editTypeButtonText( QgsVectorLayer::EditType type )
Expand Down Expand Up @@ -604,7 +607,8 @@ void QgsVectorLayerProperties::apply()
}
}
else if ( editType == QgsVectorLayer::EditRange ||
editType == QgsVectorLayer::SliderRange )
editType == QgsVectorLayer::SliderRange ||
editType == QgsVectorLayer::DialRange )
{
if ( mRanges.contains( idx ) )
{
Expand All @@ -628,7 +632,6 @@ void QgsVectorLayerProperties::apply()
}
else
{

QgsSingleSymbolDialog *sdialog =
qobject_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
QgsGraduatedSymbolDialog *gdialog =
Expand Down
8 changes: 5 additions & 3 deletions src/core/qgsvectorlayer.h
Expand Up @@ -75,9 +75,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
CheckBox, /* added in 1.4 */
FileName,
Enumeration,
Immutable, /*The attribute value should not be changed in the attribute form*/
Hidden, /*The attribute value should not be shown in the attribute form @added in 1.4 */
TextEdit /*multiline edit @added in 1.4*/
Immutable, /* The attribute value should not be changed in the attribute form*/
Hidden, /* The attribute value should not be shown in the attribute form @added in 1.4 */
TextEdit, /* multiline edit @added in 1.4*/
Calendar, /* calendar widget @added in 1.5 */
DialRange, /* dial range @added in 1.5 */
};

struct RangeData
Expand Down
93 changes: 82 additions & 11 deletions src/gui/qgsattributeeditor.cpp
Expand Up @@ -33,6 +33,9 @@
#include <QCompleter>
#include <QHBoxLayout>
#include <QPlainTextEdit>
#include <QDial>
#include <QCalendarWidget>
#include <QDialogButtonBox>

void QgsAttributeEditor::selectFileName( void )
{
Expand All @@ -55,6 +58,42 @@ void QgsAttributeEditor::selectFileName( void )
le->setText( fileName );
}

void QgsAttributeEditor::selectDate( void )
{
QPushButton *pb = qobject_cast<QPushButton *>( sender() );
if ( !pb )
return;

QWidget *hbox = qobject_cast<QWidget *>( pb->parent() );
if ( !hbox )
return;

QLineEdit *le = hbox->findChild<QLineEdit *>();
if ( !le )
return;

QDialog *dlg = new QDialog();
dlg->setWindowTitle( tr( "Select a date" ) );
QVBoxLayout *vl = new QVBoxLayout( dlg );

QCalendarWidget *cw = new QCalendarWidget( dlg );
cw->setSelectedDate( QDate::fromString( le->text(), Qt::ISODate ) );
vl->addWidget( cw );

QDialogButtonBox *buttonBox = new QDialogButtonBox( dlg );
buttonBox->addButton( QDialogButtonBox::Ok );
buttonBox->addButton( QDialogButtonBox::Cancel );
vl->addWidget( buttonBox );

connect( buttonBox, SIGNAL( accepted() ), dlg, SLOT( accept() ) );
connect( buttonBox, SIGNAL( rejected() ), dlg, SLOT( reject() ) );

if ( dlg->exec() == QDialog::Accepted )
{
le->setText( cw->selectedDate().toString( Qt::ISODate ) );
}
}

QComboBox *QgsAttributeEditor::comboBox( QWidget *editor, QWidget *parent )
{
QComboBox *cb = NULL;
Expand Down Expand Up @@ -180,6 +219,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
}
break;


case QgsVectorLayer::DialRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::EditRange:
{
Expand Down Expand Up @@ -208,12 +249,20 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
}
else
{
QSlider *sl = NULL;
QAbstractSlider *sl = NULL;

if ( editor )
sl = qobject_cast<QSlider*>( editor );
{
sl = qobject_cast<QAbstractSlider*>( editor );
}
else if ( editType == QgsVectorLayer::DialRange )
{
sl = new QDial( parent );
}
else
{
sl = new QSlider( Qt::Horizontal, parent );
}

if ( sl )
{
Expand Down Expand Up @@ -335,6 +384,7 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
break;

case QgsVectorLayer::FileName:
case QgsVectorLayer::Calendar:
{
QPushButton *pb = NULL;
QLineEdit *le = qobject_cast<QLineEdit *>( editor );
Expand Down Expand Up @@ -365,18 +415,17 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
}

if ( pb )
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
{
if ( editType == QgsVectorLayer::FileName )
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
if ( editType == QgsVectorLayer::Calendar )
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) );
}
}
break;

case QgsVectorLayer::Immutable:
return NULL;

}

if ( editType == QgsVectorLayer::Immutable )
{
myWidget->setEnabled( false );
}

setValue( myWidget, vl, idx, value );
Expand Down Expand Up @@ -448,7 +497,7 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
text = QString::number( sb->value() );
}

QSlider *slider = qobject_cast<QSlider *>( widget );
QAbstractSlider *slider = qobject_cast<QAbstractSlider *>( widget );
if ( slider )
{
text = QString::number( slider->value() );
Expand All @@ -467,6 +516,12 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
text = ckb->isChecked() ? states.first : states.second;
}

QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( widget );
if ( cw )
{
text = cw->selectedDate().toString();
}

le = widget->findChild<QLineEdit *>();
if ( le )
{
Expand Down Expand Up @@ -505,6 +560,20 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
}
}
break;
case QVariant::Date:
{
QDate myDateValue = QDate::fromString( text, Qt::ISODate );
if ( myDateValue.isValid() && !text.isEmpty() )
{
value = myDateValue;
modified = true;
}
else if ( modified )
{
value = QVariant( theField.type() );
}
}
break;
default: //string
modified = true;
value = QVariant( text );
Expand Down Expand Up @@ -542,6 +611,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
}
break;

case QgsVectorLayer::DialRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::EditRange:
{
Expand All @@ -556,7 +626,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
}
else
{
QSlider *sl = qobject_cast<QSlider *>( editor );
QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor );
if ( sl == NULL )
return false;
sl->setValue( value.toInt() );
Expand Down Expand Up @@ -615,6 +685,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
break;

case QgsVectorLayer::FileName:
case QgsVectorLayer::Calendar:
{
QLineEdit *le = editor->findChild<QLineEdit *>();
if ( le == NULL )
Expand Down
1 change: 1 addition & 0 deletions src/gui/qgsattributeeditor.h
Expand Up @@ -40,6 +40,7 @@ class GUI_EXPORT QgsAttributeEditor : public QObject

public slots:
void selectFileName( void );
void selectDate( void );
};


Expand Down

0 comments on commit f82574f

Please sign in to comment.