Skip to content

Commit

Permalink
Add shell for QgsLayoutView
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 67c6e8f commit 4c2447f
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
%Include layertree/qgslayertreeview.sip
%Include layertree/qgslayertreeviewdefaultactions.sip
%Include layout/qgslayoutdesignerinterface.sip
%Include layout/qgslayoutview.sip
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
%Include locator/qgslocatorwidget.sip
Expand Down
80 changes: 80 additions & 0 deletions python/gui/layout/qgslayoutview.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutview.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutView: QGraphicsView
{
%Docstring
A graphical widget to display and interact with QgsLayouts.

QgsLayoutView manages the layout interaction tools and mouse/key events.

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutview.h"
%End
public:

enum Tool
{
ToolSelect,
ToolAddItem,
};

QgsLayoutView( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsLayoutView.
%End

QgsLayout *currentLayout();
%Docstring
Returns the current layout associated with the view.
.. seealso:: setCurrentLayout()
.. seealso:: layoutSet()
:rtype: QgsLayout
%End

void setCurrentLayout( QgsLayout *layout /KeepReference/ );
%Docstring
Sets the current ``layout`` to edit in the view.
.. seealso:: currentLayout()
.. seealso:: layoutSet()
%End

signals:

void layoutSet( QgsLayout *layout );
%Docstring
Emitted when a ``layout`` is set for the view.
.. seealso:: currentLayout()
.. seealso:: setCurrentLayout()
%End

protected:
virtual void mousePressEvent( QMouseEvent *event );

virtual void mouseReleaseEvent( QMouseEvent *event );

virtual void mouseMoveEvent( QMouseEvent *event );

virtual void mouseDoubleClickEvent( QMouseEvent *event );


};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutview.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
47 changes: 47 additions & 0 deletions python/plugins/processing/algs/replacer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import glob

import re

#regex = re.compile(r"( *)def defineCharacteristics(self):\n(\s*)self.name, self.i18n_name = self.trAlgorithm\('(.*)'\)\n(\s*)self.group, self.i18n_group = self.trAlgorithm\('(.*)'\)", re.MULTILINE)

regex = re.compile(r"^(.*)(\s*def name)", re.M | re.DOTALL)
regex2 = re.compile(r"", re.M | re.DOTALL)
regex = re.compile(r"^(.*?)(\s*def name.*)def defineCharacteristics\(self\):\s*\n(.*?)(\s*def .*)$", re.M | re.DOTALL)
#regex = re.compile(r"(\s*)def defineCharacteristics(self):", re.MULTILINE)

for filename in glob.iglob('./**/*.py', recursive=True):
out = None
with open(filename, 'r') as myfile:
data = myfile.read()

r = regex.search(data)
if r:

out = r.groups()[0]
out += '\n\n def __init__(self):\n super().__init__()\n'
out += r.groups()[2]
out += r.groups()[1]
out += r.groups()[3]
print(out)

#r2=regex2.search(data)
#if r2:
# print(r2.groups()[1])
# print('-0-----')
# print(r2.groups()[2])

#d=regex.sub(r"\1def name(self):\n\2return '\3'\n\n\1def group(self):\n\2return '\5'\n\n\1def defineCharacteristics(self):",data)
#d=regex.sub(r"\1def defineCharacteristics(self)",data)

if out:
with open(filename, 'w') as myfile:
myfile.write(out)

if False:
d = r.group() # print(r.groups())
#print(d)
d = regex.sub(r"\1def name(self):\n\2return '\3'\n\n\1def group(self):\n\2return '\5'\n", d)
print(d)

# def group(self):
# return '[GDAL] Analysis' d)
3 changes: 3 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ SET(QGIS_GUI_SRCS
layertree/qgslayertreeview.cpp
layertree/qgslayertreeviewdefaultactions.cpp

layout/qgslayoutview.cpp

locator/qgslocator.cpp
locator/qgslocatorfilter.cpp
locator/qgslocatorwidget.cpp
Expand Down Expand Up @@ -620,6 +622,7 @@ SET(QGIS_GUI_MOC_HDRS
layertree/qgslayertreeviewdefaultactions.h

layout/qgslayoutdesignerinterface.h
layout/qgslayoutview.h

locator/qgslocator.h
locator/qgslocatorfilter.h
Expand Down
58 changes: 58 additions & 0 deletions src/gui/layout/qgslayoutview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/***************************************************************************
qgslayoutview.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 "qgslayoutview.h"
#include "qgslayout.h"

QgsLayoutView::QgsLayoutView( QWidget *parent )
: QGraphicsView( parent )
{

}

QgsLayout *QgsLayoutView::currentLayout()
{
return qobject_cast<QgsLayout *>( scene() );
}

void QgsLayoutView::setCurrentLayout( QgsLayout *layout )
{
setScene( layout );

//emit layoutSet, so that designer dialogs can update for the new layout
emit layoutSet( layout );
}

void QgsLayoutView::mousePressEvent( QMouseEvent *event )
{
QGraphicsView::mousePressEvent( event );
}

void QgsLayoutView::mouseReleaseEvent( QMouseEvent *event )
{
QGraphicsView::mouseReleaseEvent( event );
}

void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
{
QGraphicsView::mouseMoveEvent( event );
}

void QgsLayoutView::mouseDoubleClickEvent( QMouseEvent *event )
{
QGraphicsView::mouseDoubleClickEvent( event );
}
87 changes: 87 additions & 0 deletions src/gui/layout/qgslayoutview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/***************************************************************************
qgslayoutview.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 QGSLAYOUTVIEW_H
#define QGSLAYOUTVIEW_H

#include <QGraphicsView>
#include "qgis.h"
#include "qgsprevieweffect.h" // for QgsPreviewEffect::PreviewMode
#include "qgis_gui.h"

class QgsLayout;

/**
* \ingroup gui
* A graphical widget to display and interact with QgsLayouts.
*
* QgsLayoutView manages the layout interaction tools and mouse/key events.
*
* \since QGIS 3.0
*/
class GUI_EXPORT QgsLayoutView: public QGraphicsView
{

Q_OBJECT

Q_PROPERTY( QgsLayout *currentLayout READ currentLayout WRITE setCurrentLayout NOTIFY layoutSet )

public:

//! Current view tool
enum Tool
{
ToolSelect = 0, //!< Select/move/resize item tool
ToolAddItem, //!< Add new item tool
};

/**
* Constructor for QgsLayoutView.
*/
QgsLayoutView( QWidget *parent SIP_TRANSFERTHIS = nullptr );

/**
* Returns the current layout associated with the view.
* \see setCurrentLayout()
* \see layoutSet()
*/
QgsLayout *currentLayout();

/**
* Sets the current \a layout to edit in the view.
* \see currentLayout()
* \see layoutSet()
*/
void setCurrentLayout( QgsLayout *layout SIP_KEEPREFERENCE );

signals:

/**
* Emitted when a \a layout is set for the view.
* \see currentLayout()
* \see setCurrentLayout()
*/
void layoutSet( QgsLayout *layout );

protected:
void mousePressEvent( QMouseEvent *event ) override;
void mouseReleaseEvent( QMouseEvent *event ) override;
void mouseMoveEvent( QMouseEvent *event ) override;
void mouseDoubleClickEvent( QMouseEvent *event ) override;

};

#endif // QGSLAYOUTVIEW_H

0 comments on commit 4c2447f

Please sign in to comment.