Qwt源碼解讀之QwtPickerMachine類

來源:互聯網
上載者:User

Qwt為拾取操作提供了狀態機器設定,用於控制拾取操作的不同行為。

void setStateMachine( QwtPickerMachine * );

其實現如下:

/*!  Set a state machine and delete the previous one  \param stateMachine State machine  \sa stateMachine()*/void QwtPicker::setStateMachine( QwtPickerMachine *stateMachine ){    if ( d_data->stateMachine != stateMachine )    {        reset();        delete d_data->stateMachine;        d_data->stateMachine = stateMachine;        if ( d_data->stateMachine )            d_data->stateMachine->reset();    }}

這裡其實就是State模式[GOF《設計模式》]的應用。State模式的UML圖如下:

註:配圖來自http://c.chinaitlab.com/cc/basic/200904/781718.html

角色指派:

QwtPicker 相當於UML圖中的Context類;

QwtPickerMachine相當於狀態基類State; 而QwtPickerTrackerMachine, QwtPickerClickPointMachine, QwtPickerDragPointMachine, QwtPickerClickRectMachine, QwtPickerDragRectMachine, QwtPickerPolygonMachine則是具體的狀態子類。

QwtPicker::transition() 相當於Context::Request();

    virtual void transition( const QEvent * );

QwtPickerMachine::transition( )相當於Handle(); 

    //! Transition    virtual QList<Command> transition(        const QwtEventPattern &, const QEvent * ) = 0;

最後給上狀態機器類的繼承關係圖:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.