Skip to content

Commit

Permalink
Remove outdated icon support for item metadata
Browse files Browse the repository at this point in the history
Now handled in QgsLayoutItem directly
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent aafe1cc commit 49eaebb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 36 deletions.
5 changes: 0 additions & 5 deletions python/core/layout/qgslayoutitemregistry.sip
Expand Up @@ -40,11 +40,6 @@ and ``visibleName``.
int type() const;
%Docstring
Returns the unique item type code for the layout item class.
%End

virtual QIcon icon() const;
%Docstring
Returns an icon representing the layout item type.
%End

QString visibleName() const;
Expand Down
30 changes: 15 additions & 15 deletions src/core/layout/qgslayoutitemregistry.cpp
Expand Up @@ -56,29 +56,29 @@ bool QgsLayoutItemRegistry::populate()
return new TestLayoutItem( layout );
};

addLayoutItemType( new QgsLayoutItemMetadata( QgsLayoutItemRegistry::LayoutItem + 1002, QStringLiteral( "temp type" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), createTemporaryItem ) );
addLayoutItemType( new QgsLayoutItemMetadata( QgsLayoutItemRegistry::LayoutItem + 1002, QStringLiteral( "temp type" ), createTemporaryItem ) );
#endif

addLayoutItemType( new QgsLayoutItemMetadata( LayoutGroup, QObject::tr( "Group" ), QIcon(), QgsLayoutItemGroup::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutFrame, QObject::tr( "Frame" ), QIcon(), QgsLayoutFrame::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPage, QObject::tr( "Page" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ), QgsLayoutItemPage::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutMap, QObject::tr( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ), QgsLayoutItemMap::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPicture, QObject::tr( "Picture" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddImage.svg" ) ), QgsLayoutItemPicture::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutLabel, QObject::tr( "Label" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionLabel.svg" ) ), QgsLayoutItemLabel::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutLegend, QObject::tr( "Legend" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLegend.svg" ) ), QgsLayoutItemLegend::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutScaleBar, QObject::tr( "Scalebar" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionScaleBar.svg" ) ), QgsLayoutItemScaleBar::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutShape, QObject::tr( "Shape" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), []( QgsLayout * layout )
addLayoutItemType( new QgsLayoutItemMetadata( LayoutGroup, QObject::tr( "Group" ), QgsLayoutItemGroup::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutFrame, QObject::tr( "Frame" ), QgsLayoutFrame::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPage, QObject::tr( "Page" ), QgsLayoutItemPage::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutMap, QObject::tr( "Map" ), QgsLayoutItemMap::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPicture, QObject::tr( "Picture" ), QgsLayoutItemPicture::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutLabel, QObject::tr( "Label" ), QgsLayoutItemLabel::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutLegend, QObject::tr( "Legend" ), QgsLayoutItemLegend::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutScaleBar, QObject::tr( "Scalebar" ), QgsLayoutItemScaleBar::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutShape, QObject::tr( "Shape" ), []( QgsLayout * layout )
{
QgsLayoutItemShape *shape = new QgsLayoutItemShape( layout );
shape->setShapeType( QgsLayoutItemShape::Rectangle );
return shape;
} ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPolygon, QObject::tr( "Polygon" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolygon.svg" ) ), QgsLayoutItemPolygon::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPolyline, QObject::tr( "Polyline" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolyline.svg" ) ), QgsLayoutItemPolyline::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPolygon, QObject::tr( "Polygon" ), QgsLayoutItemPolygon::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPolyline, QObject::tr( "Polyline" ), QgsLayoutItemPolyline::create ) );

addLayoutMultiFrameType( new QgsLayoutMultiFrameMetadata( LayoutHtml, QObject::tr( "HTML" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddHtml.svg" ) ), QgsLayoutItemHtml::create ) );
addLayoutMultiFrameType( new QgsLayoutMultiFrameMetadata( LayoutAttributeTable, QObject::tr( "Attribute Table" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddTable.svg" ) ), QgsLayoutItemAttributeTable::create ) );
addLayoutMultiFrameType( new QgsLayoutMultiFrameMetadata( LayoutTextTable, QObject::tr( "Text Table" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddTable.svg" ) ), QgsLayoutItemTextTable::create ) );
addLayoutMultiFrameType( new QgsLayoutMultiFrameMetadata( LayoutHtml, QObject::tr( "HTML" ), QgsLayoutItemHtml::create ) );
addLayoutMultiFrameType( new QgsLayoutMultiFrameMetadata( LayoutAttributeTable, QObject::tr( "Attribute Table" ), QgsLayoutItemAttributeTable::create ) );
addLayoutMultiFrameType( new QgsLayoutMultiFrameMetadata( LayoutTextTable, QObject::tr( "Text Table" ), QgsLayoutItemTextTable::create ) );

return true;
}
Expand Down
15 changes: 2 additions & 13 deletions src/core/layout/qgslayoutitemregistry.h
Expand Up @@ -62,11 +62,6 @@ class CORE_EXPORT QgsLayoutItemAbstractMetadata
*/
int type() const { return mType; }

/**
* Returns an icon representing the layout item type.
*/
virtual QIcon icon() const { return QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ); }

/**
* Returns a translated, user visible name for the layout item class.
*/
Expand Down Expand Up @@ -119,11 +114,10 @@ class CORE_EXPORT QgsLayoutItemMetadata : public QgsLayoutItemAbstractMetadata
* Constructor for QgsLayoutItemMetadata with the specified class \a type
* and \a visibleName, and function pointers for the various item creation functions.
*/
QgsLayoutItemMetadata( int type, const QString &visibleName, const QIcon &icon,
QgsLayoutItemMetadata( int type, const QString &visibleName,
QgsLayoutItemCreateFunc pfCreate,
QgsLayoutItemPathResolverFunc pfPathResolver = nullptr )
: QgsLayoutItemAbstractMetadata( type, visibleName )
, mIcon( icon )
, mCreateFunc( pfCreate )
, mPathResolverFunc( pfPathResolver )
{}
Expand All @@ -138,7 +132,6 @@ class CORE_EXPORT QgsLayoutItemMetadata : public QgsLayoutItemAbstractMetadata
*/
QgsLayoutItemPathResolverFunc pathResolverFunction() const { return mPathResolverFunc; }

QIcon icon() const override { return mIcon.isNull() ? QgsLayoutItemAbstractMetadata::icon() : mIcon; }
QgsLayoutItem *createItem( QgsLayout *layout ) override { return mCreateFunc ? mCreateFunc( layout ) : nullptr; }

void resolvePaths( QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) override
Expand All @@ -148,7 +141,6 @@ class CORE_EXPORT QgsLayoutItemMetadata : public QgsLayoutItemAbstractMetadata
}

protected:
QIcon mIcon;
QgsLayoutItemCreateFunc mCreateFunc = nullptr;
QgsLayoutItemPathResolverFunc mPathResolverFunc = nullptr;

Expand Down Expand Up @@ -243,11 +235,10 @@ class CORE_EXPORT QgsLayoutMultiFrameMetadata : public QgsLayoutMultiFrameAbstra
* Constructor for QgsLayoutMultiFrameMetadata with the specified class \a type
* and \a visibleName, and function pointers for the various item creation functions.
*/
QgsLayoutMultiFrameMetadata( int type, const QString &visibleName, const QIcon &icon,
QgsLayoutMultiFrameMetadata( int type, const QString &visibleName,
QgsLayoutMultiFrameCreateFunc pfCreate,
QgsLayoutMultiFramePathResolverFunc pfPathResolver = nullptr )
: QgsLayoutMultiFrameAbstractMetadata( type, visibleName )
, mIcon( icon )
, mCreateFunc( pfCreate )
, mPathResolverFunc( pfPathResolver )
{}
Expand All @@ -262,7 +253,6 @@ class CORE_EXPORT QgsLayoutMultiFrameMetadata : public QgsLayoutMultiFrameAbstra
*/
QgsLayoutMultiFramePathResolverFunc pathResolverFunction() const { return mPathResolverFunc; }

QIcon icon() const override { return mIcon.isNull() ? QgsLayoutMultiFrameAbstractMetadata::icon() : mIcon; }
QgsLayoutMultiFrame *createMultiFrame( QgsLayout *layout ) override { return mCreateFunc ? mCreateFunc( layout ) : nullptr; }

void resolvePaths( QVariantMap &properties, const QgsPathResolver &pathResolver, bool saving ) override
Expand All @@ -272,7 +262,6 @@ class CORE_EXPORT QgsLayoutMultiFrameMetadata : public QgsLayoutMultiFrameAbstra
}

protected:
QIcon mIcon;
QgsLayoutMultiFrameCreateFunc mCreateFunc = nullptr;
QgsLayoutMultiFramePathResolverFunc mPathResolverFunc = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgslayoutitem.cpp
Expand Up @@ -257,7 +257,7 @@ void TestQgsLayoutItem::registry()

QSignalSpy spyTypeAdded( &registry, &QgsLayoutItemRegistry::typeAdded );

QgsLayoutItemMetadata *metadata = new QgsLayoutItemMetadata( 2, QStringLiteral( "my type" ), QIcon(), create, resolve );
QgsLayoutItemMetadata *metadata = new QgsLayoutItemMetadata( 2, QStringLiteral( "my type" ), create, resolve );
QVERIFY( registry.addLayoutItemType( metadata ) );
QCOMPARE( spyTypeAdded.count(), 1 );
QCOMPARE( spyTypeAdded.value( 0 ).at( 0 ).toInt(), 2 );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgslayoutmultiframe.cpp
Expand Up @@ -530,7 +530,7 @@ void TestQgsLayoutMultiFrame::registry()

QSignalSpy spyTypeAdded( &registry, &QgsLayoutItemRegistry::multiFrameTypeAdded );

QgsLayoutMultiFrameMetadata *metadata = new QgsLayoutMultiFrameMetadata( QgsLayoutItemRegistry::PluginItem + 1, QStringLiteral( "TestMultiFrame" ), QIcon(), create, resolve );
QgsLayoutMultiFrameMetadata *metadata = new QgsLayoutMultiFrameMetadata( QgsLayoutItemRegistry::PluginItem + 1, QStringLiteral( "TestMultiFrame" ), create, resolve );
QVERIFY( registry.addLayoutMultiFrameType( metadata ) );
QCOMPARE( spyTypeAdded.count(), 1 );
QCOMPARE( spyTypeAdded.value( 0 ).at( 0 ).toInt(), QgsLayoutItemRegistry::PluginItem + 1 );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/gui/testqgslayoutview.cpp
Expand Up @@ -320,7 +320,7 @@ void TestQgsLayoutView::guiRegistry()
//creating item
QgsLayoutItem *item = registry.createItem( uuid, nullptr );
QVERIFY( !item );
QgsApplication::layoutItemRegistry()->addLayoutItemType( new QgsLayoutItemMetadata( QgsLayoutItemRegistry::LayoutItem + 101, QStringLiteral( "my type" ), QIcon(), []( QgsLayout * layout )->QgsLayoutItem*
QgsApplication::layoutItemRegistry()->addLayoutItemType( new QgsLayoutItemMetadata( QgsLayoutItemRegistry::LayoutItem + 101, QStringLiteral( "my type" ), []( QgsLayout * layout )->QgsLayoutItem*
{
return new TestItem( layout );
} ) );
Expand Down

0 comments on commit 49eaebb

Please sign in to comment.