Skip to content
Permalink
Browse files

Add settings editor to options dialog

  • Loading branch information
m-kuhn committed Sep 21, 2015
1 parent c0aacb7 commit 591942e6b9029b57a731ac90138c958457253ddb
@@ -507,6 +507,7 @@
<file>themes/default/cadtools/perpendicular.png</file>
<file>themes/default/mIconSuccess.png</file>
<file>themes/default/mIconClear.png</file>
<file>themes/default/mIconWarning.svg</file>
<file>flags/zh.png</file>
<file>themes/default/mIconPaintEffects.svg</file>
<file>themes/default/mActionCircularStringCurvePoint.png</file>
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.0"
width="420"
height="373"
viewBox="0 0 413.435 365.722"
id="svg2"
xml:space="preserve"><defs
id="defs13"><linearGradient
id="linearGradient5211"><stop
style="stop-color:#ffffff;stop-opacity:0.62886596"
offset="0"
id="stop5213" /><stop
style="stop-color:#ffffff;stop-opacity:0"
offset="1"
id="stop5215" /></linearGradient><linearGradient
id="linearGradient2893"><stop
style="stop-color:#ffffff;stop-opacity:0.57396448"
offset="0"
id="stop2895" /><stop
style="stop-color:#ffffff;stop-opacity:0.25098041"
offset="0.19"
id="stop2897" /><stop
style="stop-color:#6b6b6b;stop-opacity:0.1254902"
offset="0.60000002"
id="stop2901" /><stop
style="stop-color:#000000;stop-opacity:0.1254902"
offset="1"
id="stop2899" /></linearGradient><radialGradient
cx="847.04108"
cy="615.58044"
r="300"
fx="847.04108"
fy="615.58044"
id="radialGradient3236"
xlink:href="#linearGradient2893"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1.215027,0,0,1.266667,-841.03957,-591.10063)" /><linearGradient
id="linearGradient3139"><stop
style="stop-color:#ffff00;stop-opacity:1"
offset="0"
id="stop3141" /><stop
style="stop-color:#ffffe8;stop-opacity:1"
offset="1"
id="stop3143" /></linearGradient>

<linearGradient
x1="5.4911467e-05"
y1="182.86166"
x2="413.43466"
y2="182.86166"
id="linearGradient4105"
xlink:href="#linearGradient3139"
gradientUnits="userSpaceOnUse" /><linearGradient
x1="109.46228"
y1="322.42599"
x2="246.50478"
y2="-79.847679"
id="linearGradient5196"
xlink:href="#linearGradient3139"
gradientUnits="userSpaceOnUse" /><radialGradient
cx="173.78099"
cy="150.8327"
r="206.90388"
fx="173.78099"
fy="150.8327"
id="radialGradient5217"
xlink:href="#linearGradient5211"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-0.6101056,0.6619819,-0.6829184,-0.6294014,402.98608,80.149634)" /></defs>
<path
d="M 222.96725,25.584927 C 222.96725,25.584927 217.87808,14.575759 207.42113,14.576744 C 196.96419,14.576744 191.86222,25.583943 191.86222,25.583943 L 18.46388,325.93617 C 18.46388,325.93617 11.475854,335.84777 16.70383,344.90494 C 21.932792,353.96112 34.016889,352.87438 34.016889,352.87438 L 380.82931,352.8852 C 380.82931,352.8852 392.9075,353.98179 398.13548,344.92562 C 403.36444,335.87041 396.38232,325.94897 396.38232,325.94897 L 222.96725,25.584927 z "
style="fill:#ffff00;fill-opacity:1;fill-rule:nonzero;stroke:#df1800;stroke-width:21.65608788;stroke-linecap:round;stroke-linejoin:round"
id="path5" />
<g
transform="matrix(0.9843676,0,0,0.9843676,3.9346133,3.7486992)"
id="Ebene_3">
<path
d="M 244.087,136.653 C 243.021,141.087 223.689,221.907 221.288,231.408 C 218.888,240.91 216.62,249.914 214.481,258.419 C 214.481,258.419 213.37,263.785 207.558,263.785 L 205.806,263.785 C 199.994,263.785 198.883,258.419 198.883,258.419 C 196.744,249.914 194.477,240.91 192.076,231.408 C 189.676,221.907 170.347,141.087 169.278,136.653 C 155.581,79.854 258.166,78.283 244.087,136.653 z "
id="path8" />
<circle
cx="206.717"
cy="308.54599"
r="24.256001"
id="circle10" />
</g>
<g
style="display:inline"
id="layer1"><path
d="M 207.42187,3.7486992 C 190.78921,3.7486992 183.55747,17.86399 182.4743,20.175334 L 9.0717821,320.53052 L 9.1025436,320.53052 C 7.6189352,322.6589 -0.9830227,335.92595 7.3183772,350.30764 C 15.640504,364.72096 31.490758,363.90595 34.01935,363.68889 C 34.060847,363.68533 34.170035,363.69206 34.203919,363.68889 L 380.82439,363.71965 L 380.82439,363.68889 C 383.40046,363.90935 399.21989,364.7256 407.52536,350.3384 C 415.85694,335.91028 407.17871,322.58813 405.7412,320.53052 L 405.77196,320.53052 L 232.46173,20.390665 L 232.33868,20.175334 C 231.24163,17.833999 224.03503,3.7471353 207.42187,3.7486992 z "
style="fill:url(#radialGradient5217);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:22;stroke-linecap:round;stroke-linejoin:round;stroke-opacity:1"
id="path5192" /></g></svg>
@@ -848,6 +848,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
mVariableEditor->reloadContext();
mVariableEditor->setEditableScopeIndex( 0 );

mAdvancedSettingsEditor->setSettingsObject( &settings );

// restore window and widget geometry/state
restoreOptionsBaseUi();
}
@@ -862,7 +864,7 @@ void QgsOptions::setCurrentPage( QString pageWidgetName )
//find the page with a matching widget name
for ( int idx = 0; idx < mOptionsStackedWidget->count(); ++idx )
{
QWidget * currentPage = mOptionsStackedWidget->widget( idx );
QWidget* currentPage = mOptionsStackedWidget->widget( idx );
if ( currentPage->objectName() == pageWidgetName )
{
//found the page, set it as current
@@ -42,30 +42,30 @@

#include "qgsvariantdelegate.h"

QgsVariantDelegate::QgsVariantDelegate( QObject *parent )
QgsVariantDelegate::QgsVariantDelegate( QObject* parent )
: QItemDelegate( parent )
{
boolExp.setPattern( "true|false" );
boolExp.setCaseSensitivity( Qt::CaseInsensitive );
mBoolExp.setPattern( "true|false" );
mBoolExp.setCaseSensitivity( Qt::CaseInsensitive );

byteArrayExp.setPattern( "[\\x00-\\xff]*" );
charExp.setPattern( "." );
colorExp.setPattern( "\\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\\)" );
doubleExp.setPattern( "" );
pointExp.setPattern( "\\((-?[0-9]*),(-?[0-9]*)\\)" );
rectExp.setPattern( "\\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\\)" );
signedIntegerExp.setPattern( "-?[0-9]*" );
sizeExp = pointExp;
unsignedIntegerExp.setPattern( "[0-9]*" );
mByteArrayExp.setPattern( "[\\x00-\\xff]*" );
mCharExp.setPattern( "." );
mColorExp.setPattern( "\\(([0-9]*),([0-9]*),([0-9]*),([0-9]*)\\)" );
mDoubleExp.setPattern( "" );
mPointExp.setPattern( "\\((-?[0-9]*),(-?[0-9]*)\\)" );
mRectExp.setPattern( "\\((-?[0-9]*),(-?[0-9]*),(-?[0-9]*),(-?[0-9]*)\\)" );
mSignedIntegerExp.setPattern( "-?[0-9]*" );
mSizeExp = mPointExp;
mUnsignedIntegerExp.setPattern( "[0-9]*" );

dateExp.setPattern( "([0-9]{,4})-([0-9]{,2})-([0-9]{,2})" );
timeExp.setPattern( "([0-9]{,2}):([0-9]{,2}):([0-9]{,2})" );
dateTimeExp.setPattern( dateExp.pattern() + "T" + timeExp.pattern() );
mDateExp.setPattern( "([0-9]{,4})-([0-9]{,2})-([0-9]{,2})" );
mTimeExp.setPattern( "([0-9]{,2}):([0-9]{,2}):([0-9]{,2})" );
mDateTimeExp.setPattern( mDateExp.pattern() + "T" + mTimeExp.pattern() );
}

void QgsVariantDelegate::paint( QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index ) const
void QgsVariantDelegate::paint( QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
if ( index.column() == 2 )
{
@@ -82,95 +82,96 @@ void QgsVariantDelegate::paint( QPainter *painter,
QItemDelegate::paint( painter, option, index );
}

QWidget *QgsVariantDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem & /* option */,
const QModelIndex &index ) const
QWidget* QgsVariantDelegate::createEditor( QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index ) const
{
Q_UNUSED( option )
if ( index.column() != 2 )
return 0;

QVariant originalValue = index.model()->data( index, Qt::UserRole );
if ( !isSupportedType( QgsVariantDelegate::type( originalValue ) ) )
return 0;

QLineEdit *lineEdit = new QLineEdit( parent );
QLineEdit* lineEdit = new QLineEdit( parent );
lineEdit->setFrame( false );

QRegExp regExp;

switch ( QgsVariantDelegate::type( originalValue ) )
{
case QVariant::Bool:
regExp = boolExp;
regExp = mBoolExp;
break;
case QVariant::ByteArray:
regExp = byteArrayExp;
regExp = mByteArrayExp;
break;
case QVariant::Char:
regExp = charExp;
regExp = mCharExp;
break;
case QVariant::Color:
regExp = colorExp;
regExp = mColorExp;
break;
case QVariant::Date:
regExp = dateExp;
regExp = mDateExp;
break;
case QVariant::DateTime:
regExp = dateTimeExp;
regExp = mDateTimeExp;
break;
case QVariant::Double:
regExp = doubleExp;
regExp = mDoubleExp;
break;
case QVariant::Int:
case QVariant::LongLong:
regExp = signedIntegerExp;
regExp = mSignedIntegerExp;
break;
case QVariant::Point:
regExp = pointExp;
regExp = mPointExp;
break;
case QVariant::Rect:
regExp = rectExp;
regExp = mRectExp;
break;
case QVariant::Size:
regExp = sizeExp;
regExp = mSizeExp;
break;
case QVariant::Time:
regExp = timeExp;
regExp = mTimeExp;
break;
case QVariant::UInt:
case QVariant::ULongLong:
regExp = unsignedIntegerExp;
regExp = mUnsignedIntegerExp;
break;
default:
;
}

if ( !regExp.isEmpty() )
{
QValidator *validator = new QRegExpValidator( regExp, lineEdit );
QValidator* validator = new QRegExpValidator( regExp, lineEdit );
lineEdit->setValidator( validator );
}

return lineEdit;
}

void QgsVariantDelegate::setEditorData( QWidget *editor,
const QModelIndex &index ) const
void QgsVariantDelegate::setEditorData( QWidget* editor,
const QModelIndex& index ) const
{
QVariant value = index.model()->data( index, Qt::UserRole );
if ( QLineEdit *lineEdit = qobject_cast<QLineEdit *>( editor ) )
if ( QLineEdit* lineEdit = qobject_cast<QLineEdit* >( editor ) )
lineEdit->setText( displayText( value ) );
}

void QgsVariantDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index ) const
void QgsVariantDelegate::setModelData( QWidget* editor, QAbstractItemModel* model,
const QModelIndex& index ) const
{
QLineEdit *lineEdit = qobject_cast<QLineEdit *>( editor );
QLineEdit* lineEdit = qobject_cast<QLineEdit* >( editor );
if ( !lineEdit->isModified() )
return;

QString text = lineEdit->text();
const QValidator *validator = lineEdit->validator();
const QValidator* validator = lineEdit->validator();
if ( validator )
{
int pos;
@@ -187,11 +188,11 @@ void QgsVariantDelegate::setModelData( QWidget *editor, QAbstractItemModel *mode
value = text.at( 0 );
break;
case QVariant::Color:
colorExp.exactMatch( text );
value = QColor( qMin( colorExp.cap( 1 ).toInt(), 255 ),
qMin( colorExp.cap( 2 ).toInt(), 255 ),
qMin( colorExp.cap( 3 ).toInt(), 255 ),
qMin( colorExp.cap( 4 ).toInt(), 255 ) );
mColorExp.exactMatch( text );
value = QColor( qMin( mColorExp.cap( 1 ).toInt(), 255 ),
qMin( mColorExp.cap( 2 ).toInt(), 255 ),
qMin( mColorExp.cap( 3 ).toInt(), 255 ),
qMin( mColorExp.cap( 4 ).toInt(), 255 ) );
break;
case QVariant::Date:
{
@@ -210,17 +211,17 @@ void QgsVariantDelegate::setModelData( QWidget *editor, QAbstractItemModel *mode
}
break;
case QVariant::Point:
pointExp.exactMatch( text );
value = QPoint( pointExp.cap( 1 ).toInt(), pointExp.cap( 2 ).toInt() );
mPointExp.exactMatch( text );
value = QPoint( mPointExp.cap( 1 ).toInt(), mPointExp.cap( 2 ).toInt() );
break;
case QVariant::Rect:
rectExp.exactMatch( text );
value = QRect( rectExp.cap( 1 ).toInt(), rectExp.cap( 2 ).toInt(),
rectExp.cap( 3 ).toInt(), rectExp.cap( 4 ).toInt() );
mRectExp.exactMatch( text );
value = QRect( mRectExp.cap( 1 ).toInt(), mRectExp.cap( 2 ).toInt(),
mRectExp.cap( 3 ).toInt(), mRectExp.cap( 4 ).toInt() );
break;
case QVariant::Size:
sizeExp.exactMatch( text );
value = QSize( sizeExp.cap( 1 ).toInt(), sizeExp.cap( 2 ).toInt() );
mSizeExp.exactMatch( text );
value = QSize( mSizeExp.cap( 1 ).toInt(), mSizeExp.cap( 2 ).toInt() );
break;
case QVariant::StringList:
value = text.split( "," );
@@ -269,7 +270,7 @@ bool QgsVariantDelegate::isSupportedType( QVariant::Type type )
}
}

QString QgsVariantDelegate::displayText( const QVariant &value )
QString QgsVariantDelegate::displayText( const QVariant& value )
{
switch ( QgsVariantDelegate::type( value ) )
{
@@ -325,7 +326,7 @@ QString QgsVariantDelegate::displayText( const QVariant &value )
}

/* hack to get "real" type of a variant, because QVariant::type() almost always returns QString */
QVariant::Type QgsVariantDelegate::type( const QVariant &value )
QVariant::Type QgsVariantDelegate::type( const QVariant& value )
{
if ( value.type() == QVariant::String )
{

0 comments on commit 591942e

Please sign in to comment.
You can’t perform that action at this time.