-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port base class for item configuration widgets
- Loading branch information
1 parent
a3e2678
commit 72bf292
Showing
5 changed files
with
415 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/layout/qgslayoutitemwidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
class QgsLayoutConfigObject: QObject | ||
{ | ||
%Docstring | ||
|
||
An object for property widgets for layout items. All layout config type widgets should contain | ||
this object. | ||
|
||
If you are creating a new QgsLayoutItem configuration widget, you should instead | ||
inherit from QgsLayoutItemBaseWidget (rather then directly working with QgsLayoutConfigObject). | ||
|
||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslayoutitemwidget.h" | ||
%End | ||
public: | ||
|
||
QgsLayoutConfigObject( QWidget *parent /TransferThis/, QgsLayoutObject *layoutObject ); | ||
%Docstring | ||
Constructor for QgsLayoutConfigObject, linked with the specified ``layoutObject``. | ||
%End | ||
|
||
void initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty key ); | ||
%Docstring | ||
Registers a data defined ``button``, setting up its initial value, connections and description. | ||
The corresponding property ``key`` must be specified. | ||
%End | ||
|
||
void updateDataDefinedButton( QgsPropertyOverrideButton *button ); | ||
%Docstring | ||
Updates a data defined button to reflect the item's current properties. | ||
%End | ||
|
||
QgsVectorLayer *coverageLayer() const; | ||
%Docstring | ||
Returns the current layout context coverage layer (if set). | ||
:rtype: QgsVectorLayer | ||
%End | ||
|
||
|
||
}; | ||
|
||
class QgsLayoutItemBaseWidget: QgsPanelWidget | ||
{ | ||
%Docstring | ||
|
||
A base class for property widgets for layout items. All layout item widgets should inherit from | ||
this base class. | ||
|
||
|
||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslayoutitemwidget.h" | ||
%End | ||
public: | ||
|
||
QgsLayoutItemBaseWidget( QWidget *parent /TransferThis/, QgsLayoutObject *layoutObject ); | ||
%Docstring | ||
Constructor for QgsLayoutItemBaseWidget, linked with the specified ``layoutObject``. | ||
%End | ||
|
||
protected: | ||
|
||
void registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property ); | ||
%Docstring | ||
Registers a data defined ``button``, setting up its initial value, connections and description. | ||
The corresponding property ``key`` must be specified. | ||
%End | ||
|
||
void updateDataDefinedButton( QgsPropertyOverrideButton *button ); | ||
%Docstring | ||
Updates a previously registered data defined button to reflect the item's current properties. | ||
%End | ||
|
||
QgsVectorLayer *coverageLayer() const; | ||
%Docstring | ||
Returns the current layout context coverage layer (if set). | ||
:rtype: QgsVectorLayer | ||
%End | ||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/layout/qgslayoutitemwidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/*************************************************************************** | ||
qgslayoutitemwidget.cpp | ||
------------------------ | ||
Date : July 2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayoutitemwidget.h" | ||
#include "qgspropertyoverridebutton.h" | ||
#include "qgslayout.h" | ||
|
||
|
||
// | ||
// QgsLayoutConfigObject | ||
// | ||
|
||
QgsLayoutConfigObject::QgsLayoutConfigObject( QWidget *parent, QgsLayoutObject *layoutObject ) | ||
: QObject( parent ) | ||
, mLayoutObject( layoutObject ) | ||
{ | ||
#if 0 //TODO | ||
connect( atlasComposition(), &QgsAtlasComposition::coverageLayerChanged, | ||
this, [ = ] { updateDataDefinedButtons(); } ); | ||
connect( atlasComposition(), &QgsAtlasComposition::toggled, this, &QgsComposerConfigObject::updateDataDefinedButtons ); | ||
#endif | ||
} | ||
|
||
void QgsLayoutConfigObject::updateDataDefinedProperty() | ||
{ | ||
//match data defined button to item's data defined property | ||
QgsPropertyOverrideButton *ddButton = qobject_cast<QgsPropertyOverrideButton *>( sender() ); | ||
if ( !ddButton ) | ||
{ | ||
return; | ||
} | ||
QgsLayoutObject::DataDefinedProperty key = QgsLayoutObject::NoProperty; | ||
|
||
if ( ddButton->propertyKey() >= 0 ) | ||
key = static_cast< QgsLayoutObject::DataDefinedProperty >( ddButton->propertyKey() ); | ||
|
||
if ( key == QgsLayoutObject::NoProperty ) | ||
{ | ||
return; | ||
} | ||
|
||
//set the data defined property and refresh the item | ||
if ( mLayoutObject ) | ||
{ | ||
mLayoutObject->dataDefinedProperties().setProperty( key, ddButton->toProperty() ); | ||
mLayoutObject->refresh(); | ||
} | ||
} | ||
|
||
void QgsLayoutConfigObject::updateDataDefinedButtons() | ||
{ | ||
#if 0 //TODO | ||
Q_FOREACH ( QgsPropertyOverrideButton *button, findChildren< QgsPropertyOverrideButton * >() ) | ||
{ | ||
button->setVectorLayer( atlasCoverageLayer() ); | ||
} | ||
#endif | ||
} | ||
|
||
void QgsLayoutConfigObject::initializeDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty key ) | ||
{ | ||
button->blockSignals( true ); | ||
button->init( key, mLayoutObject->dataDefinedProperties(), QgsLayoutObject::propertyDefinitions(), coverageLayer() ); | ||
connect( button, &QgsPropertyOverrideButton::changed, this, &QgsLayoutConfigObject::updateDataDefinedProperty ); | ||
button->registerExpressionContextGenerator( mLayoutObject ); | ||
button->blockSignals( false ); | ||
} | ||
|
||
void QgsLayoutConfigObject::updateDataDefinedButton( QgsPropertyOverrideButton *button ) | ||
{ | ||
if ( !button ) | ||
return; | ||
|
||
if ( button->propertyKey() < 0 || !mLayoutObject ) | ||
return; | ||
|
||
QgsLayoutObject::DataDefinedProperty key = static_cast< QgsLayoutObject::DataDefinedProperty >( button->propertyKey() ); | ||
whileBlocking( button )->setToProperty( mLayoutObject->dataDefinedProperties().property( key ) ); | ||
} | ||
|
||
#if 0 // TODO | ||
QgsAtlasComposition *QgsLayoutConfigObject::atlasComposition() const | ||
{ | ||
if ( !mLayoutObject ) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
QgsComposition *composition = mComposerObject->composition(); | ||
|
||
if ( !composition ) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
return &composition->atlasComposition(); | ||
} | ||
#endif | ||
|
||
QgsVectorLayer *QgsLayoutConfigObject::coverageLayer() const | ||
{ | ||
if ( !mLayoutObject ) | ||
return nullptr; | ||
|
||
QgsLayout *layout = mLayoutObject->layout(); | ||
if ( !layout ) | ||
return nullptr; | ||
|
||
return layout->context().layer(); | ||
} | ||
|
||
|
||
// | ||
// QgsLayoutItemBaseWidget | ||
// | ||
|
||
QgsLayoutItemBaseWidget::QgsLayoutItemBaseWidget( QWidget *parent, QgsLayoutObject *layoutObject ) | ||
: QgsPanelWidget( parent ) | ||
, mConfigObject( new QgsLayoutConfigObject( this, layoutObject ) ) | ||
{ | ||
|
||
} | ||
|
||
void QgsLayoutItemBaseWidget::registerDataDefinedButton( QgsPropertyOverrideButton *button, QgsLayoutObject::DataDefinedProperty property ) | ||
{ | ||
mConfigObject->initializeDataDefinedButton( button, property ); | ||
} | ||
|
||
void QgsLayoutItemBaseWidget::updateDataDefinedButton( QgsPropertyOverrideButton *button ) | ||
{ | ||
mConfigObject->updateDataDefinedButton( button ); | ||
} | ||
|
||
QgsVectorLayer *QgsLayoutItemBaseWidget::coverageLayer() const | ||
{ | ||
return mConfigObject->coverageLayer(); | ||
} | ||
|
||
#if 0 //TODO | ||
QgsAtlasComposition *QgsLayoutItemBaseWidget::atlasComposition() const | ||
{ | ||
return mConfigObject->atlasComposition(); | ||
} | ||
#endif |
Oops, something went wrong.