Qt编程:IPProcessGrid 类

   IPProcessGrid 类是 ImagePlay 图像处理软件的核心组件之一,负责管理和渲染图像处理流程图,并控制处理流程的执行。它继承自 QGraphicsView,并实现了IPLPropertyChangedEventHandler 和 IPLOutputsChangedEventHandler 接口,用于响应属性变化和输出变化事件。

//#############################################################################
//
//  This file is part of ImagePlay.
//
//  ImagePlay 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 3 of the License, or
//  (at your option) any later version.
//
//  ImagePlay is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with ImagePlay.  If not, see <http://www.gnu.org/licenses/>.
//
//#############################################################################

#ifndef IPPROCESSGRID_H
#define IPPROCESSGRID_H

#include <QGraphicsView>
#include <QGraphicsScene>
#include <QDragEnterEvent>
#include <QMainWindow>
#include <QStatusBar>
#include <QScrollBar>
#include <QQueue>
#include <QElapsedTimer>
#include <QApplication>

#include "IPProcessStep.h"
#include "IPProcessGridScene.h"
#include "IPProcessThread.h"
#include "IPZoomWidget.h"

class IPProcessGridScene;
class MainWindow;

//-----------------------------------------------------------------------------
//!IPProcessGrid represents the process graph
/*!
 * This custom QGraphicsView manages the proceses, connections and renders
 * everything as a process graph.
 * All items are stored in IPProcessGridScene.
 * The graph traversation and process exectution is also handled here.
 */
class IPProcessGrid : public QGraphicsView, public IPLPropertyChangedEventHandler, public IPLOutputsChangedEventHandler
{
    Q_OBJECT
public:
    explicit                IPProcessGrid           (QWidget *parent = 0);
    void                    zoomIn                  ();
    void                    zoomOut                 ();
    void                    zoomBy                  (float scaleChange);
    void                    zoomTo                  (float scale);
    static bool             sortTreeDepthLessThan   (IPProcessStep* s1, IPProcessStep* s2);
    void                    buildQueue              ();
    int                     executeThread           (IPLProcess* process, IPLImage *image = NULL, int inputIndex = 0, bool useOpenCV = false);
    void                    propagateNeedsUpdate    (IPLProcess* process);
    void                    propagateResultReady    (IPLProcess *process, bool resultReady);
    void                    propertyChanged         (IPLProcess *);
    void                    outputsChanged          (IPLProcess *);
    void                    setSequenceIndex        (int index);
    void                    setSequenceRunning      (bool status)                           { _isSequenceRunning = status; }
    void                    setMainWindow           (MainWindow* mainWindow)                { _mainWindow = mainWindow; }
    void                    requestUpdate           ();
    MainWindow*             mainWindow              ()                                      { return _mainWindow; }
    IPProcessGridScene*     scene                   ()                                      { return _scene; }
    void                    stopExecution           ()                                      { _stopExecution = true; }
    bool                    isRunning               ()                                      { return _isRunning; }

signals:
    void                    sequenceChanged         (int index, int count);

public slots:
    void                    execute                 (bool forcedUpdate = false);
    void                    terminate               ();
    void                    updateProgress          (int);
    void                    sceneRectChanged        (const QRectF & rect);

private:
    void                    fitLargeSceneRect();

    IPProcessGridScene*     _scene;                 //!< Scene
    float                   _scale;                 //!< Scale for zooming
    MainWindow*             _mainWindow;            //!< MainWindow
    bool                    _isRunning;             //!< Is running
    bool                    _updateNeeded;
    IPProcessStep*          _currentStep;           //!< Currently active step, settings shown on the left side
    QList<IPProcessStep*>   _processList;           //!< Ordered process list
    int                     _sequenceCount;         //!< Image sequence count
    int                     _sequenceIndex;         //!< Current image sequence index
    int                     _lastSequenceIndex;     //!< Last image sequence index
    bool                    _isSequenceRunning;     //!< Is sequence running
    bool                    _lastProcessSuccess;    //!< Last process was successful
    bool                    _stopExecution;         //!< Used to stop the execution early
    bool                    _longProcess;           //!< Unmeasurable processes must update GUI regularly
    IPProcessThread*        _thread;                //!< Reference to the current thread

    // QWidget interface
protected:
    virtual void            wheelEvent              (QWheelEvent *)     override;
    virtual void            resizeEvent             (QResizeEvent *)    override;
    virtual void            keyPressEvent           (QKeyEvent *)       override;
    virtual void            keyReleaseEvent         (QKeyEvent *)       override;
    virtual void            showEvent               (QShowEvent *)      override;
};

#endif // IPPROCESSGRID_H
//#############################################################################
//
//  This file is part of ImagePlay.
//
//  ImagePlay 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 3 of the License, or
//  (at your option) any later version.
//
//  ImagePlay is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with ImagePlay.  If not, see <http://www.gnu.org/licenses/>.
//
//#############################################################################

#include "IPProcessGrid.h"

IPProcessGrid::IPProcessGrid(QWidget *parent) : QGraphicsView(parent)
{
    _scene = new IPProcessGridScene(this);

    setScene(_scene);
    setAlignment(Qt::AlignLeft | Qt::AlignTop);
    setRender
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值