Skip to content
Permalink
Browse files
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 f82574f7000986ce175ea643f37af60e8153cfbb
@@ -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();
@@ -217,6 +217,7 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy

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

@@ -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;
@@ -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 ) )
@@ -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];
@@ -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 )
{
@@ -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;

@@ -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 )
@@ -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() );
@@ -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:
@@ -550,6 +568,9 @@ void QgsAttributeTypeDialog::accept()
case 10:
mEditType = QgsVectorLayer::TextEdit;
break;
case 11:
mEditType = QgsVectorLayer::Calendar;
break;
}

QDialog::accept();
@@ -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:
@@ -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 )
@@ -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 ) )
{
@@ -628,7 +632,6 @@ void QgsVectorLayerProperties::apply()
}
else
{

QgsSingleSymbolDialog *sdialog =
qobject_cast < QgsSingleSymbolDialog * >( widgetStackRenderers->currentWidget() );
QgsGraduatedSymbolDialog *gdialog =
@@ -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
@@ -33,6 +33,9 @@
#include <QCompleter>
#include <QHBoxLayout>
#include <QPlainTextEdit>
#include <QDial>
#include <QCalendarWidget>
#include <QDialogButtonBox>

void QgsAttributeEditor::selectFileName( void )
{
@@ -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;
@@ -180,6 +219,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
}
break;


case QgsVectorLayer::DialRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::EditRange:
{
@@ -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 )
{
@@ -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 );
@@ -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 );
@@ -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() );
@@ -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 )
{
@@ -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 );
@@ -542,6 +611,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
}
break;

case QgsVectorLayer::DialRange:
case QgsVectorLayer::SliderRange:
case QgsVectorLayer::EditRange:
{
@@ -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() );
@@ -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 )
@@ -40,6 +40,7 @@ class GUI_EXPORT QgsAttributeEditor : public QObject

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


Loading

0 comments on commit f82574f

Please sign in to comment.