Logo Search packages:      
Sourcecode: webissues version File versions  Download package

view.h

/**************************************************************************
* This file is part of the WebIssues program
* Copyright (C) 2006 Michał Męciński
* Copyright (C) 2007 WebIssues Team
*
* 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 VIEW_H
#define VIEW_H

#include <QWidget>

#include "xmlui/client.h"
#include "data/datarows.h"

class KConfig;

namespace WebIssues
{

class UpdateEvent;
class UpdateBatch;
class ViewEvent;

/**
* A view which can be embedded in a window.
*
* This is a base class for creating views which consist of a widget
* of any type and a set of actions which can be plugged into the
* container window's menus and toolbars.
*
* Inherited classes should create the main widget, create actions
* and load the XMLGUI configuration file. The initialUpdate() method
* should be overriden to perform initialization after embedding
* the view in the container window.
*
* A view may have an identifier which is used to distinguish units
* of data the view is associated with. The identifier is set before
* initialUpdate() and is not changed later.
*
* The view class provides a few properties and signals to communicate
* with the container. It provides a caption, size hint and setting
* status messages.
*
* The view automatically registers itself to receive update events
* from the data manager. It also handles executing update batches.
*
* The ViewManager can be used to create and activate views.
* It can also post ViewEvent events to all views of a given class
* for communication between views.
*/
00056 class View : public QObject, public XmlUi::Client
{
    Q_OBJECT
public:
    /**
    * Constructor.
    *
    * @param parent The parent object.
    */
    View( QObject* parent );

    /**
    * Destructor.
    */
    ~View();

public:
    /**
    * Return the main widget of the view.
    */
00076     QWidget* mainWidget() const { return m_mainWidget; }

    /**
    * Return the default size of the view.
    */
00081     QSize viewerSizeHint() const { return m_sizeHint; }

    /**
    * Return the caption of the view.
    */
00086     const QString& caption() const { return m_caption; }

    /**
    * Return the identifier of the data unit.
    */
00091     int id() const { return m_id; }

    /**
    * Set the identifier of the data unit.
    */
00096     void setId( int id ) { m_id = id; }

    /**
    * Return the state of the view.
    */
00101     bool isEnabled() const { return m_enabled; }

    /**
    * Return the access mode of the view.
    */
00106     Access access() const { return m_access; }

public:
    /**
    * Update after embedding in the container.
    *
    * Override this method to perform initialization of the view.
    */
    virtual void initialUpdate();

    /**
    * Switch the view to enabled state.
    */
    virtual void enableView();

    /**
    * Switch the view to disabled state.
    */
    virtual void disableView();

    /**
    * Switch between normal and administrator access.
    *
    * Override this method to show or hide administrative actions.
    */
    virtual void updateAccess( Access access );

    /**
    * Ask the view if it can be closed.
    *
    * Override this method to ask the user about unsaved changes.
    *
    * The default implementation returns @c true.
    *
    * @return @c true if the view can be closed, @c false otherwise.
    */
    virtual bool queryClose();

signals:
    /**
    * Emitted when the caption was changed.
    *
    * @param text The new caption.
    */
    void captionChanged( const QString& text );

    /**
    * Emitted when the view is enabled or disabled.
    *
    * @param enabled The state of the view.
    */
    void enabledChanged( bool enabled );

    /**
    * Emitted when an information message should be displayed.
    *
    * @param text The status message.
    */
    void showInfo( const QString& text );

    /**
    * Emitted when a warning message should be displayed.
    *
    * @param text The status message.
    */
    void showWarning( const QString& text );

    /**
    * Emitted when a busy message should be displayed.
    *
    * @param text The status message.
    */
    void showBusy( const QString& text );

    /**
    * Emitted when a summary message should be displayed.
    *
    * @param pixmap The summary pixmap.
    * @param text The summary message.
    */
    void showSummary( const QPixmap& pixmap, const QString& text );

protected:
    /**
    * Handle the UpdateEvent from the data manager.
    *
    * @param e The update event.
    */
    virtual void updateEvent( UpdateEvent* e );

    /**
    * Handle the ViewEvent from the view manager.
    *
    * @param e The view event.
    */
    virtual void viewEvent( ViewEvent* e );

protected:
    /**
    * Set the main widget of the view.
    */
    void setMainWidget( QWidget* widget );

    /**
    * Set the default size of the view.
    */
    void setViewerSizeHint( const QSize& size );

    /**
    * Set the dynamic access mode of the view
    */
    void setAccess( Access access, bool initial = false );

    /**
    * Start executing the update batch.
    *
    * @param batch The batch to execute.
    */
    void executeUpdate( UpdateBatch* batch );

    /**
    * Return @c true if an update batch is being executed.
    */
00229     bool isUpdating() const { return m_updating; }

protected: // overrides
    void customEvent( QEvent* e );

protected slots:
    void setCaption( const QString& text );

private slots:
    void updateCompleted( bool successful );

private:
    QWidget* m_mainWidget;

    QSize m_sizeHint;

    QString m_caption;

    int m_id;

    Access m_access;
    bool m_enabled;

    bool m_updating;
};

}

#endif

Generated by  Doxygen 1.6.0   Back to index