QWidget *QgsComposerColumnWidthDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const { Q_UNUSED( index ); Q_UNUSED( option ); QgsDoubleSpinBox *editor = new QgsDoubleSpinBox( parent ); editor->setMinimum( 0 ); editor->setMaximum( 1000 ); editor->setDecimals( 2 ); editor->setSuffix( tr( " mm" ) ); editor->setSpecialValueText( tr( "Automatic" ) ); editor->setShowClearButton( true ); return editor; }
void TestQgsDoubleSpinBox::clear() { QgsDoubleSpinBox* spinBox = new QgsDoubleSpinBox(); spinBox->setMaximum( 10.0 ); spinBox->setMinimum( 1.0 ); spinBox->setValue( 5.0 ); spinBox->setClearValueMode( QgsDoubleSpinBox::MinimumValue ); spinBox->clear(); QCOMPARE( spinBox->value(), 1.0 ); QCOMPARE( spinBox->clearValue(), 1.0 ); spinBox->setClearValueMode( QgsDoubleSpinBox::MaximumValue ); spinBox->clear(); QCOMPARE( spinBox->value(), 10.0 ); QCOMPARE( spinBox->clearValue(), 10.0 ); spinBox->setClearValue( 7.0 ); spinBox->clear(); QCOMPARE( spinBox->value(), 7.0 ); QCOMPARE( spinBox->clearValue(), 7.0 ); delete spinBox; }
void TestQgsDoubleSpinBox::expression() { QgsDoubleSpinBox* spinBox = new QgsDoubleSpinBox(); spinBox->setMinimum( -10.0 ); spinBox->setMaximum( 10.0 ); spinBox->setValue( 1.0 ); spinBox->setExpressionsEnabled( false ); QCOMPARE( spinBox->valueFromText( QString( "5" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "5+2" ) ), -10.0 ); spinBox->setExpressionsEnabled( true ); QCOMPARE( spinBox->valueFromText( QString( "5" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "5+2" ) ), 7.0 ); spinBox->setClearValue( 3.0 ); spinBox->setShowClearButton( true ); QCOMPARE( spinBox->valueFromText( QString( "" ) ), 3.0 ); //clearing should set to clearValue spinBox->setShowClearButton( false ); spinBox->setValue( 8.0 ); QCOMPARE( spinBox->valueFromText( QString( "" ) ), 8.0 ); //if no clear button, clearing should set to previous value spinBox->setShowClearButton( true ); spinBox->setValue( 4.0 ); QCOMPARE( spinBox->valueFromText( QString( "5/" ) ), 4.0 ); //invalid expression should reset to previous value //suffix tests spinBox->setSuffix( QString( "mm" ) ); spinBox->setExpressionsEnabled( false ); QCOMPARE( spinBox->valueFromText( QString( "5mm" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "5+2mm" ) ), -10.0 ); spinBox->setExpressionsEnabled( true ); QCOMPARE( spinBox->valueFromText( QString( "5 mm" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "5+2 mm" ) ), 7.0 ); QCOMPARE( spinBox->valueFromText( QString( "5mm" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "5+2mm" ) ), 7.0 ); spinBox->setClearValue( 3.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm" ) ), 3.0 ); //clearing should set to clearValue QCOMPARE( spinBox->valueFromText( QString( "" ) ), 3.0 ); spinBox->setValue( 4.0 ); QCOMPARE( spinBox->valueFromText( QString( "5/mm" ) ), 4.0 ); //invalid expression should reset to previous value //prefix tests spinBox->setSuffix( QString() ); spinBox->setPrefix( QString( "mm" ) ); spinBox->setExpressionsEnabled( false ); QCOMPARE( spinBox->valueFromText( QString( "mm5" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm5+2" ) ), -10.0 ); spinBox->setExpressionsEnabled( true ); QCOMPARE( spinBox->valueFromText( QString( "mm 5" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm 5+2" ) ), 7.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm5" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm5+2" ) ), 7.0 ); spinBox->setClearValue( 3.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm" ) ), 3.0 ); //clearing should set to clearValue QCOMPARE( spinBox->valueFromText( QString( "" ) ), 3.0 ); spinBox->setValue( 4.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm5/" ) ), 4.0 ); //invalid expression should reset to previous value //both suffix and prefix spinBox->setSuffix( QString( "ll" ) ); spinBox->setPrefix( QString( "mm" ) ); spinBox->setExpressionsEnabled( true ); QCOMPARE( spinBox->valueFromText( QString( "mm 5 ll" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm 5+2 ll" ) ), 7.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm5ll" ) ), 5.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm5+2ll" ) ), 7.0 ); spinBox->setClearValue( 3.0 ); QCOMPARE( spinBox->valueFromText( QString( "mmll" ) ), 3.0 ); //clearing should set to clearValue QCOMPARE( spinBox->valueFromText( QString( "" ) ), 3.0 ); spinBox->setValue( 4.0 ); QCOMPARE( spinBox->valueFromText( QString( "mm5/ll" ) ), 4.0 ); //invalid expression should reset to previous value delete spinBox; }