Skip to content

Commit

Permalink
Add a lot of framework code for showing item properties in designer
Browse files Browse the repository at this point in the history
And hook up a non-functional page properties widget which is
shown when right clicking on a page in the view.
  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent 0f90e23 commit 20029c2
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 12 deletions.
15 changes: 14 additions & 1 deletion python/gui/layout/qgslayoutitemguiregistry.sip
Expand Up @@ -28,7 +28,14 @@ class QgsLayoutItemAbstractGuiMetadata
%End
public:

QgsLayoutItemAbstractGuiMetadata( int type, const QString &groupId = QString() );
enum Flag
{
FlagNoCreationTools,
};
typedef QFlags<QgsLayoutItemAbstractGuiMetadata::Flag> Flags;


QgsLayoutItemAbstractGuiMetadata( int type, const QString &groupId = QString(), Flags flags = 0 );
%Docstring
Constructor for QgsLayoutItemAbstractGuiMetadata with the specified class ``type``.

Expand All @@ -43,6 +50,12 @@ class QgsLayoutItemAbstractGuiMetadata
:rtype: int
%End

Flags flags() const;
%Docstring
Returns item flags.
:rtype: Flags
%End

QString groupId() const;
%Docstring
Returns the item group ID, if set.
Expand Down
2 changes: 2 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -158,6 +158,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutaddpagesdialog.cpp
layout/qgslayoutdesignerdialog.cpp
layout/qgslayoutappmenuprovider.cpp
layout/qgslayoutpagepropertieswidget.cpp

locator/qgsinbuiltlocatorfilters.cpp
locator/qgslocatoroptionswidget.cpp
Expand Down Expand Up @@ -337,6 +338,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutaddpagesdialog.h
layout/qgslayoutappmenuprovider.h
layout/qgslayoutdesignerdialog.h
layout/qgslayoutpagepropertieswidget.h

locator/qgsinbuiltlocatorfilters.h
locator/qgslocatoroptionswidget.h
Expand Down
11 changes: 6 additions & 5 deletions src/app/layout/qgslayoutappmenuprovider.cpp
Expand Up @@ -15,12 +15,14 @@

#include "qgslayoutappmenuprovider.h"
#include "qgslayoutitempage.h"
#include "qgslayoutdesignerdialog.h"
#include "qgslayout.h"
#include <QMenu>
#include <QMessageBox>

QgsLayoutAppMenuProvider::QgsLayoutAppMenuProvider( QObject *parent )
: QObject( parent )
QgsLayoutAppMenuProvider::QgsLayoutAppMenuProvider( QgsLayoutDesignerDialog *designer )
: QObject( nullptr )
, mDesigner( designer )
{

}
Expand All @@ -34,10 +36,9 @@ QMenu *QgsLayoutAppMenuProvider::createContextMenu( QWidget *parent, QgsLayout *
if ( page )
{
QAction *pagePropertiesAction = new QAction( tr( "Page Properties…" ), menu );
connect( pagePropertiesAction, &QAction::triggered, this, [page]()
connect( pagePropertiesAction, &QAction::triggered, this, [this, page]()
{


mDesigner->showItemOptions( page );
} );
menu->addAction( pagePropertiesAction );
QAction *removePageAction = new QAction( tr( "Remove Page" ), menu );
Expand Down
8 changes: 7 additions & 1 deletion src/app/layout/qgslayoutappmenuprovider.h
Expand Up @@ -20,6 +20,8 @@
#include "qgslayoutview.h"
#include <QObject>

class QgsLayoutDesignerDialog;

/**
* A menu provider for QgsLayoutView
*/
Expand All @@ -29,10 +31,14 @@ class QgsLayoutAppMenuProvider : public QObject, public QgsLayoutViewMenuProvide

public:

QgsLayoutAppMenuProvider( QObject *parent = nullptr );
QgsLayoutAppMenuProvider( QgsLayoutDesignerDialog *designer );

QMenu *createContextMenu( QWidget *parent, QgsLayout *layout, QPointF layoutPoint ) const override;

private:

QgsLayoutDesignerDialog *mDesigner = nullptr;

};

#endif // QGSLAYOUTAPPMENUPROVIDER_H
60 changes: 59 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -27,10 +27,15 @@
#include "qgslayoutviewtoolpan.h"
#include "qgslayoutviewtoolzoom.h"
#include "qgslayoutviewtoolselect.h"
#include "qgslayoutitemwidget.h"
#include "qgsgui.h"
#include "qgslayoutitemguiregistry.h"
#include "qgslayoutruler.h"
#include "qgslayoutaddpagesdialog.h"
#include "qgspanelwidgetstack.h"
#include "qgspanelwidget.h"
#include "qgsdockwidget.h"
#include "qgslayoutpagepropertieswidget.h"
#include <QShortcut>
#include <QComboBox>
#include <QLineEdit>
Expand All @@ -44,6 +49,8 @@ QList<double> QgsLayoutDesignerDialog::sStatusZoomLevelsList { 0.125, 0.25, 0.5,
#define FIT_LAYOUT -101
#define FIT_LAYOUT_WIDTH -102

bool QgsLayoutDesignerDialog::sInitializedRegistry = false;

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
, mDesigner( dialog )
Expand All @@ -70,6 +77,10 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
, mInterface( new QgsAppLayoutDesignerInterface( this ) )
, mToolsActionGroup( new QActionGroup( this ) )
{
if ( !sInitializedRegistry )
{
initializeRegistry();
}
QgsSettings settings;
int size = settings.value( QStringLiteral( "IconSize" ), QGIS_ICON_SIZE ).toInt();
setIconSize( QSize( size, size ) );
Expand Down Expand Up @@ -222,9 +233,22 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla

connect( mActionToggleFullScreen, &QAction::toggled, this, &QgsLayoutDesignerDialog::toggleFullScreen );

mMenuProvider = new QgsLayoutAppMenuProvider();
mMenuProvider = new QgsLayoutAppMenuProvider( this );
mView->setMenuProvider( mMenuProvider );

int minDockWidth( fontMetrics().width( QStringLiteral( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) ) );

mItemDock = new QgsDockWidget( tr( "Item properties" ), this );
mItemDock->setObjectName( QStringLiteral( "ItemDock" ) );
mItemDock->setMinimumWidth( minDockWidth );
mItemPropertiesStack = new QgsPanelWidgetStack();
mItemDock->setWidget( mItemPropertiesStack );
mPanelsMenu->addAction( mItemDock->toggleViewAction() );

addDockWidget( Qt::RightDockWidgetArea, mItemDock );

mItemDock->show();

restoreWindowState();
}

Expand Down Expand Up @@ -257,6 +281,25 @@ void QgsLayoutDesignerDialog::setIconSizes( int size )
}
}

void QgsLayoutDesignerDialog::showItemOptions( QgsLayoutItem *item )
{
if ( !item )
{
delete mItemPropertiesStack->takeMainPanel();
return;
}

std::unique_ptr< QgsLayoutItemBaseWidget > widget( QgsGui::layoutItemGuiRegistry()->createItemWidget( item ) );
if ( ! widget )
{
return;
}

delete mItemPropertiesStack->takeMainPanel();
widget->setDockMode( true );
mItemPropertiesStack->setMainPanel( widget.release() );
}

void QgsLayoutDesignerDialog::open()
{
show();
Expand Down Expand Up @@ -302,6 +345,9 @@ void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )

void QgsLayoutDesignerDialog::itemTypeAdded( int type )
{
if ( QgsGui::layoutItemGuiRegistry()->itemMetadata( type )->flags() & QgsLayoutItemAbstractGuiMetadata::FlagNoCreationTools )
return;

QString name = QgsApplication::layoutItemRegistry()->itemMetadata( type )->visibleName();
QString groupId = QgsGui::layoutItemGuiRegistry()->itemMetadata( type )->groupId();
QToolButton *groupButton = nullptr;
Expand Down Expand Up @@ -532,4 +578,16 @@ void QgsLayoutDesignerDialog::activateNewItemCreationTool( int type )
}
}

void QgsLayoutDesignerDialog::initializeRegistry()
{
sInitializedRegistry = true;
auto createPageWidget = ( []( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return new QgsLayoutPagePropertiesWidget( nullptr, item );
} );

QgsGui::layoutItemGuiRegistry()->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutPage, QIcon(), createPageWidget, nullptr, QString(), QgsLayoutItemAbstractGuiMetadata::FlagNoCreationTools ) );

}


14 changes: 14 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -32,6 +32,9 @@ class QComboBox;
class QSlider;
class QLabel;
class QgsLayoutAppMenuProvider;
class QgsLayoutItem;
class QgsPanelWidgetStack;
class QgsDockWidget;

class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
Expand Down Expand Up @@ -90,6 +93,10 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void setIconSizes( int size );

/**
* Shows the configuration widget for the specified layout \a item.
*/
void showItemOptions( QgsLayoutItem *item );

public slots:

Expand Down Expand Up @@ -138,6 +145,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

private:

static bool sInitializedRegistry;

QgsAppLayoutDesignerInterface *mInterface = nullptr;

QgsLayout *mLayout = nullptr;
Expand Down Expand Up @@ -170,6 +179,9 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

QgsLayoutAppMenuProvider *mMenuProvider;

QgsDockWidget *mItemDock = nullptr;
QgsPanelWidgetStack *mItemPropertiesStack = nullptr;

//! Save window state
void saveWindowState();

Expand All @@ -179,6 +191,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
//! Switch to new item creation tool, for a new item of the specified \a type.
void activateNewItemCreationTool( int type );

void initializeRegistry();

};

#endif // QGSLAYOUTDESIGNERDIALOG_H
Expand Down
25 changes: 25 additions & 0 deletions src/app/layout/qgslayoutpagepropertieswidget.cpp
@@ -0,0 +1,25 @@
/***************************************************************************
qgslayoutpagepropertieswidget.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 "qgslayoutpagepropertieswidget.h"
#include "qgslayoutitempage.h"

QgsLayoutPagePropertiesWidget::QgsLayoutPagePropertiesWidget( QWidget *parent, QgsLayoutItem *layoutItem )
: QgsLayoutItemBaseWidget( parent, layoutItem )
, mPage( static_cast< QgsLayoutItemPage *>( layoutItem ) )
{
setupUi( this );

}
52 changes: 52 additions & 0 deletions src/app/layout/qgslayoutpagepropertieswidget.h
@@ -0,0 +1,52 @@
/***************************************************************************
qgslayoutpagepropertieswidget.h
-------------------------------
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. *
* *
***************************************************************************/

#ifndef QGSLAYOUTPAGEPROPERTIESWIDGET_H
#define QGSLAYOUTPAGEPROPERTIESWIDGET_H

#include "qgis.h"
#include "ui_qgslayoutpagepropertieswidget.h"

#include "qgslayoutsize.h"
#include "qgslayoutpoint.h"
#include "qgslayoutitemwidget.h"
#include "qgslayoutmeasurementconverter.h"

class QgsLayoutItem;
class QgsLayoutItemPage;

/**
* A widget for configuring properties of pages in a layout
*/
class QgsLayoutPagePropertiesWidget : public QgsLayoutItemBaseWidget, private Ui::QgsLayoutPagePropertiesWidget
{
Q_OBJECT

public:

/**
* Constructor for QgsLayoutPagePropertiesWidget.
*/
QgsLayoutPagePropertiesWidget( QWidget *parent, QgsLayoutItem *page );

private:

QgsLayoutItemPage *mPage = nullptr;

QgsLayoutMeasurementConverter mConverter;

};

#endif // QGSLAYOUTPAGEPROPERTIESWIDGET_H
2 changes: 2 additions & 0 deletions src/core/layout/qgslayoutitemregistry.cpp
Expand Up @@ -42,6 +42,8 @@ bool QgsLayoutItemRegistry::populate()
};

addLayoutItemType( new QgsLayoutItemMetadata( 101, QStringLiteral( "temp type" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), createTemporaryItem ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPage, QStringLiteral( "Page" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ), nullptr ) );

addLayoutItemType( new QgsLayoutItemMetadata( LayoutRectangle, QStringLiteral( "Rectangle" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), QgsLayoutItemRectangularShape::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutEllipse, QStringLiteral( "Ellipse" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicCircle.svg" ) ), QgsLayoutItemEllipseShape::create ) );
addLayoutItemType( new QgsLayoutItemMetadata( LayoutTriangle, QStringLiteral( "Triangle" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicTriangle.svg" ) ), QgsLayoutItemTriangleShape::create ) );
Expand Down

0 comments on commit 20029c2

Please sign in to comment.