mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Bit less Python
This commit is contained in:
parent
8845b535c5
commit
b84bf68dab
@ -10,6 +10,8 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class QgsModelDesignerDialog : QMainWindow
|
||||
{
|
||||
%Docstring
|
||||
@ -47,7 +49,6 @@ Model designer dialog base class
|
||||
QLineEdit *textName();
|
||||
QLineEdit *textGroup();
|
||||
QTreeWidget *inputsTree();
|
||||
QgsProcessingToolboxTreeView *algorithmsTree();
|
||||
|
||||
QgsMessageBar *messageBar();
|
||||
QGraphicsView *view();
|
||||
|
@ -405,6 +405,7 @@ level group containing recently used algorithms.
|
||||
Returns the underlying source Processing toolbox model.
|
||||
%End
|
||||
|
||||
|
||||
void setFilters( QgsProcessingToolboxProxyModel::Filters filters );
|
||||
%Docstring
|
||||
Set ``filters`` that affect how toolbox content is filtered.
|
||||
|
@ -49,8 +49,7 @@ from qgis.core import (Qgis,
|
||||
QgsProcessingModelParameter,
|
||||
QgsProcessingParameterType,
|
||||
)
|
||||
from qgis.gui import (QgsProcessingToolboxProxyModel,
|
||||
QgsProcessingParameterDefinitionDialog,
|
||||
from qgis.gui import (QgsProcessingParameterDefinitionDialog,
|
||||
QgsProcessingParameterWidgetContext,
|
||||
QgsModelGraphicsScene,
|
||||
QgsModelDesignerDialog)
|
||||
@ -68,22 +67,6 @@ from qgis.utils import iface
|
||||
pluginPath = os.path.split(os.path.dirname(__file__))[0]
|
||||
|
||||
|
||||
class ModelerToolboxModel(QgsProcessingToolboxProxyModel):
|
||||
|
||||
def __init__(self, parent=None, registry=None, recentLog=None):
|
||||
super().__init__(parent, registry, recentLog)
|
||||
|
||||
def flags(self, index):
|
||||
f = super().flags(index)
|
||||
source_index = self.mapToSource(index)
|
||||
if self.toolboxModel().isAlgorithm(source_index):
|
||||
f = f | Qt.ItemIsDragEnabled
|
||||
return f
|
||||
|
||||
def supportedDragActions(self):
|
||||
return Qt.CopyAction
|
||||
|
||||
|
||||
class ModelerDialog(QgsModelDesignerDialog):
|
||||
ALG_ITEM = 'ALG_ITEM'
|
||||
PROVIDER_ITEM = 'PROVIDER_ITEM'
|
||||
@ -137,9 +120,6 @@ class ModelerDialog(QgsModelDesignerDialog):
|
||||
self.view().ensureVisible(0, 0, 10, 10)
|
||||
self.view().scale(QgsApplication.desktop().logicalDpiX() / 96, QgsApplication.desktop().logicalDpiX() / 96)
|
||||
|
||||
self.algorithms_model = ModelerToolboxModel(self, QgsApplication.processingRegistry())
|
||||
self.algorithmsTree().setToolboxProxyModel(self.algorithms_model)
|
||||
|
||||
# Connect signals and slots
|
||||
self.inputsTree().doubleClicked.connect(self._addInput)
|
||||
|
||||
@ -473,8 +453,8 @@ class ModelerDialog(QgsModelDesignerDialog):
|
||||
maxX = max([alg.position().x() for alg in list(self.model().childAlgorithms().values())])
|
||||
maxY = max([alg.position().y() for alg in list(self.model().childAlgorithms().values())])
|
||||
newX = min(MARGIN + BOX_WIDTH + maxX, self.CANVAS_SIZE - BOX_WIDTH)
|
||||
newY = min(MARGIN + BOX_HEIGHT + maxY, self.CANVAS_SIZE -
|
||||
BOX_HEIGHT)
|
||||
newY = min(MARGIN + BOX_HEIGHT + maxY, self.CANVAS_SIZE
|
||||
- BOX_HEIGHT)
|
||||
else:
|
||||
newX = MARGIN + BOX_WIDTH / 2
|
||||
newY = MARGIN * 2 + BOX_HEIGHT + BOX_HEIGHT / 2
|
||||
|
@ -33,6 +33,30 @@
|
||||
///@cond NOT_STABLE
|
||||
|
||||
|
||||
QgsModelerToolboxModel::QgsModelerToolboxModel( QObject *parent )
|
||||
: QgsProcessingToolboxProxyModel( parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Qt::ItemFlags QgsModelerToolboxModel::flags( const QModelIndex &index ) const
|
||||
{
|
||||
Qt::ItemFlags f = QgsProcessingToolboxProxyModel::flags( index );
|
||||
const QModelIndex sourceIndex = mapToSource( index );
|
||||
if ( toolboxModel()->isAlgorithm( sourceIndex ) )
|
||||
{
|
||||
f = f | Qt::ItemIsDragEnabled;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
Qt::DropActions QgsModelerToolboxModel::supportedDragActions() const
|
||||
{
|
||||
return Qt::CopyAction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags flags )
|
||||
: QMainWindow( parent, flags )
|
||||
{
|
||||
@ -89,6 +113,9 @@ QgsModelDesignerDialog::QgsModelDesignerDialog( QWidget *parent, Qt::WindowFlags
|
||||
mAlgorithmsTree->setDragDropMode( QTreeWidget::DragOnly );
|
||||
mAlgorithmsTree->setDropIndicatorShown( true );
|
||||
|
||||
mAlgorithmsModel = new QgsModelerToolboxModel( this );
|
||||
mAlgorithmsTree->setToolboxProxyModel( mAlgorithmsModel );
|
||||
|
||||
connect( mView, &QgsModelGraphicsView::algorithmDropped, this, [ = ]( const QString & algorithmId, const QPointF & pos )
|
||||
{
|
||||
addAlgorithm( algorithmId, pos );
|
||||
|
@ -20,11 +20,26 @@
|
||||
#include "qgis_gui.h"
|
||||
#include "ui_qgsmodeldesignerdialogbase.h"
|
||||
|
||||
#include "qgsprocessingtoolboxmodel.h"
|
||||
|
||||
class QgsMessageBar;
|
||||
class QgsProcessingModelAlgorithm;
|
||||
|
||||
///@cond NOT_STABLE
|
||||
|
||||
#ifndef SIP_RUN
|
||||
|
||||
class GUI_EXPORT QgsModelerToolboxModel : public QgsProcessingToolboxProxyModel
|
||||
{
|
||||
public:
|
||||
explicit QgsModelerToolboxModel( QObject *parent = nullptr );
|
||||
Qt::ItemFlags flags( const QModelIndex &index ) const override;
|
||||
Qt::DropActions supportedDragActions() const override;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup gui
|
||||
* \brief Model designer dialog base class
|
||||
@ -55,7 +70,6 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
|
||||
QLineEdit *textName() { return mNameEdit; }
|
||||
QLineEdit *textGroup() { return mGroupEdit; }
|
||||
QTreeWidget *inputsTree() { return mInputsTreeWidget; }
|
||||
QgsProcessingToolboxTreeView *algorithmsTree() { return mAlgorithmsTree; }
|
||||
|
||||
QgsMessageBar *messageBar() { return mMessageBar; }
|
||||
QGraphicsView *view() { return mView; }
|
||||
@ -76,6 +90,7 @@ class GUI_EXPORT QgsModelDesignerDialog : public QMainWindow, public Ui::QgsMode
|
||||
private:
|
||||
|
||||
QgsMessageBar *mMessageBar = nullptr;
|
||||
QgsModelerToolboxModel *mAlgorithmsModel = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
@ -666,6 +666,11 @@ QgsProcessingToolboxModel *QgsProcessingToolboxProxyModel::toolboxModel()
|
||||
return mModel;
|
||||
}
|
||||
|
||||
const QgsProcessingToolboxModel *QgsProcessingToolboxProxyModel::toolboxModel() const
|
||||
{
|
||||
return mModel;
|
||||
}
|
||||
|
||||
void QgsProcessingToolboxProxyModel::setFilters( QgsProcessingToolboxProxyModel::Filters filters )
|
||||
{
|
||||
mFilters = filters;
|
||||
|
@ -450,6 +450,12 @@ class GUI_EXPORT QgsProcessingToolboxProxyModel: public QSortFilterProxyModel
|
||||
*/
|
||||
QgsProcessingToolboxModel *toolboxModel();
|
||||
|
||||
/**
|
||||
* Returns the underlying source Processing toolbox model.
|
||||
* \note Not available in Python bindings
|
||||
*/
|
||||
const QgsProcessingToolboxModel *toolboxModel() const SIP_SKIP;
|
||||
|
||||
/**
|
||||
* Set \a filters that affect how toolbox content is filtered.
|
||||
* \see filters()
|
||||
|
Loading…
x
Reference in New Issue
Block a user