mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Move method for detecting project colors to QgsProperty
This commit is contained in:
parent
da53f145f2
commit
ac10769809
@ -311,6 +311,13 @@ Returns true if preparation was successful.
|
|||||||
%Docstring
|
%Docstring
|
||||||
Returns the set of any fields referenced by the property for a specified
|
Returns the set of any fields referenced by the property for a specified
|
||||||
expression context.
|
expression context.
|
||||||
|
%End
|
||||||
|
|
||||||
|
bool isProjectColor() const;
|
||||||
|
%Docstring
|
||||||
|
Returns true if the property is set to a linked project color.
|
||||||
|
|
||||||
|
.. versionadded:: 3.6
|
||||||
%End
|
%End
|
||||||
|
|
||||||
QVariant value( const QgsExpressionContext &context, const QVariant &defaultValue = QVariant(), bool *ok /Out/ = 0 ) const;
|
QVariant value( const QgsExpressionContext &context, const QVariant &defaultValue = QVariant(), bool *ok /Out/ = 0 ) const;
|
||||||
|
@ -418,6 +418,13 @@ QSet<QString> QgsProperty::referencedFields( const QgsExpressionContext &context
|
|||||||
return QSet<QString>();
|
return QSet<QString>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QgsProperty::isProjectColor() const
|
||||||
|
{
|
||||||
|
QRegularExpression rx( QStringLiteral( "^project_color\\('.*'\\)$" ) );
|
||||||
|
return d->type == QgsProperty::ExpressionBasedProperty && !d->expressionString.isEmpty()
|
||||||
|
&& rx.match( d->expressionString ).hasMatch();
|
||||||
|
}
|
||||||
|
|
||||||
QVariant QgsProperty::propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
|
QVariant QgsProperty::propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
|
||||||
{
|
{
|
||||||
if ( ok )
|
if ( ok )
|
||||||
|
@ -352,6 +352,13 @@ class CORE_EXPORT QgsProperty
|
|||||||
*/
|
*/
|
||||||
QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext() ) const;
|
QSet< QString > referencedFields( const QgsExpressionContext &context = QgsExpressionContext() ) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the property is set to a linked project color.
|
||||||
|
*
|
||||||
|
* \since QGIS 3.6
|
||||||
|
*/
|
||||||
|
bool isProjectColor() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the current value of the property, including any transforms which are set for the property
|
* Calculates the current value of the property, including any transforms which are set for the property
|
||||||
* \param context QgsExpressionContext to evaluate the property for. The variables and functions contained
|
* \param context QgsExpressionContext to evaluate the property for. The variables and functions contained
|
||||||
|
@ -854,13 +854,7 @@ void QgsPropertyOverrideButton::updateSiblingWidgets( bool state )
|
|||||||
{
|
{
|
||||||
if ( state && mFlags & FlagDisableCheckedWidgetOnlyWhenProjectColorSet )
|
if ( state && mFlags & FlagDisableCheckedWidgetOnlyWhenProjectColorSet )
|
||||||
{
|
{
|
||||||
state = false;
|
state = mProperty.isProjectColor();
|
||||||
QRegularExpression rx( QStringLiteral( "^project_color\\('.*'\\)$" ) );
|
|
||||||
if ( mProperty.propertyType() == QgsProperty::ExpressionBasedProperty && !mExpressionString.isEmpty()
|
|
||||||
&& rx.match( mExpressionString ).hasMatch() )
|
|
||||||
{
|
|
||||||
state = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_FOREACH ( const SiblingWidget &sw, mSiblingWidgets )
|
Q_FOREACH ( const SiblingWidget &sw, mSiblingWidgets )
|
||||||
|
@ -92,6 +92,7 @@ class TestQgsProperty : public QObject
|
|||||||
void collectionStack(); //test for QgsPropertyCollectionStack
|
void collectionStack(); //test for QgsPropertyCollectionStack
|
||||||
void curveTransform();
|
void curveTransform();
|
||||||
void asVariant();
|
void asVariant();
|
||||||
|
void isProjectColor();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -1778,6 +1779,22 @@ void TestQgsProperty::asVariant()
|
|||||||
QCOMPARE( fromVar.field(), QStringLiteral( "field1" ) );
|
QCOMPARE( fromVar.field(), QStringLiteral( "field1" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsProperty::isProjectColor()
|
||||||
|
{
|
||||||
|
QgsProperty p = QgsProperty::fromValue( 3, true );
|
||||||
|
QVERIFY( !p.isProjectColor() );
|
||||||
|
p = QgsProperty::fromField( QStringLiteral( "blah" ), true );
|
||||||
|
QVERIFY( !p.isProjectColor() );
|
||||||
|
p = QgsProperty::fromExpression( QStringLiteral( "1+2" ), true );
|
||||||
|
QVERIFY( !p.isProjectColor() );
|
||||||
|
p = QgsProperty::fromExpression( QStringLiteral( "project_color('mine')" ), true );
|
||||||
|
QVERIFY( p.isProjectColor() );
|
||||||
|
p = QgsProperty::fromExpression( QStringLiteral( "project_color('burnt pineapple Skin 76')" ), true );
|
||||||
|
QVERIFY( p.isProjectColor() );
|
||||||
|
p.setActive( false );
|
||||||
|
QVERIFY( p.isProjectColor() );
|
||||||
|
}
|
||||||
|
|
||||||
void TestQgsProperty::checkCurveResult( const QList<QgsPointXY> &controlPoints, const QVector<double> &x, const QVector<double> &y )
|
void TestQgsProperty::checkCurveResult( const QList<QgsPointXY> &controlPoints, const QVector<double> &x, const QVector<double> &y )
|
||||||
{
|
{
|
||||||
// build transform
|
// build transform
|
||||||
|
Loading…
x
Reference in New Issue
Block a user