Home · All Classes · Main Classes · Deprecated
Public Slots | Public Member Functions | Static Public Attributes | Protected Slots | Protected Member Functions | Properties

MWidgetController Class Reference

MWidgetController is the base class for a controller in the MVC widget model. More...

Inheritance diagram for MWidgetController:
Inheritance graph
[legend]
Collaboration diagram for MWidgetController:
Collaboration graph
[legend]

List of all members.

Public Slots

void setViewType (const MTheme::ViewType &type)
virtual void setActive (bool active)
virtual void setObjectName (const QString &name)
void setStyleName (const QString &name)

Public Member Functions

 MWidgetController (QGraphicsItem *parent=0)
 MWidgetController (MWidgetModel *model, QGraphicsItem *parent=0)
virtual ~MWidgetController ()
void setModel (MWidgetModel *model)
MWidgetModelmodel ()
const MWidgetModelmodel () const
M::Position layoutPosition () const
void setLayoutPosition (M::Position layoutPosition)
MTheme::ViewType viewType () const
bool isActive () const
virtual void setView (MWidgetView *view)
const QStringstyleName () const

Static Public Attributes

static const MTheme::ViewType defaultType = "default"

Protected Slots

virtual void updateData (const QList< const char * > &modifications)
virtual void setupModel ()
void updateMicroFocus ()

Protected Member Functions

virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
virtual void cancelEvent (MCancelEvent *event)
virtual void orientationChangeEvent (MOrientationChangeEvent *event)
virtual void tapAndHoldGestureEvent (QGestureEvent *event, QTapAndHoldGesture *gesture)
virtual void panGestureEvent (QGestureEvent *event, QPanGesture *gesture)
virtual void pinchGestureEvent (QGestureEvent *event, QPinchGesture *gesture)
virtual void tapGestureEvent (QGestureEvent *event, QTapGesture *gesture)
virtual void swipeGestureEvent (QGestureEvent *event, QSwipeGesture *gesture)
virtual bool sceneEventFilter (QGraphicsItem *watched, QEvent *event)
virtual QVariant itemChange (GraphicsItemChange change, const QVariant &value)
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
MWidgetStyleContainerstyle ()
const MWidgetStyleContainerstyle () const
const MWidgetViewview () const

Properties

MTheme::ViewType viewType
bool active
QString styleName

Detailed Description

MWidgetController is the base class for a controller in the MVC widget model.

MWidgetController is the base class of all components that implement the Model-View-Controller pattern for widgets. In a widget, the controller serves as the public interface to the application developer. The controller internally stores the widget's state in the model and delegates painting and event handling to the view.

Although the controller provides methods to set the view and model components, widgets derived from MWidgetController always provide an already initialised model while a view is constructed at the time it is needed unless otherwise explicitly set.

Definition at line 51 of file corelib/widgets/core/mwidgetcontroller.h.


Constructor & Destructor Documentation

MWidgetController::MWidgetController ( QGraphicsItem parent = 0  )  [explicit]

Creates a new MWidgetController with the given parent.

Definition at line 79 of file mwidgetcontroller.cpp.

                                                          :
    MWidget(*new MWidgetControllerPrivate, parent)
{
    Q_D(MWidgetController);
    d->setModel(new MWidgetModel);

    MWidgetControllerPrivate::allSystemWidgets.insert(this);
}

Here is the call graph for this function:

MWidgetController::MWidgetController ( MWidgetModel model,
QGraphicsItem parent = 0 
) [explicit]

Creates a new MWidgetController with the given model and parent.

If model is 0, a MWidgetModel will be created.

Definition at line 88 of file mwidgetcontroller.cpp.

                                                                               :
    MWidget(*new MWidgetControllerPrivate, parent)
{
    Q_D(MWidgetController);
    d->setModel(model == NULL ? new MWidgetModel : model);

    MWidgetControllerPrivate::allSystemWidgets.insert(this);
}

Here is the call graph for this function:

MWidgetController::~MWidgetController (  )  [virtual]

Destroys the controller.

Definition at line 109 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);

    // let the model know that we're not attached to it anymore.
    if (d->model) {
        d->model->decreaseReferenceCount();
        d->model = 0;
    }

    // let the view know that it can now animate away.
    if (d->view) {
        // TODO: later this should probably be done by MSceneManager.
        d->view->destroy();
        d->view = 0;
    }

    MWidgetControllerPrivate::allSystemWidgets.remove(this);
}

Here is the call graph for this function:


Member Function Documentation

void MWidgetController::cancelEvent ( MCancelEvent event  )  [protected, virtual]

MWidgetController's implementation of cancelEvent() forwards the call to the view.

See also:
MWidgetView::cancelEvent()

Reimplemented from MWidget.

Definition at line 393 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (view()) {
        d->view->cancelEvent(event);
    }
}

Here is the call graph for this function:

QVariant MWidgetController::inputMethodQuery ( Qt::InputMethodQuery  query  )  const [protected, virtual]

MWidgetController's implementation of inputMethodQuery() forwards the call to the view.

See also:
MWidgetView::inputMethodQuery()

Definition at line 461 of file mwidgetcontroller.cpp.

{
    Q_D(const MWidgetController);
    if (view()) {
        return d->view->inputMethodQuery(query);
    } else {
        return QVariant();
    }
}

Here is the call graph for this function:

bool MWidgetController::isActive (  )  const

Indicates whether this widget is an active state.

See also:
setActive() MWidgetView::setActive()

Reimplemented in MCompleter.

Definition at line 481 of file mwidgetcontroller.cpp.

{
    Q_D(const MWidgetController);
    return d->active;
}

QVariant MWidgetController::itemChange ( GraphicsItemChange  change,
const QVariant value 
) [protected, virtual]

MWidgetController's implementation of itemChange() forwards the call to the view.

See also:
MWidgetView::itemChange()

Reimplemented from QGraphicsWidget.

Definition at line 450 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (d->view) {
        // forward the event to the view
        d->view->notifyItemChange(change, value);
    }
    return MWidget::itemChange(change, value);
}

M::Position MWidgetController::layoutPosition (  )  const

Definition at line 221 of file mwidgetcontroller.cpp.

{
    return model()->layoutPosition();
}

Here is the call graph for this function:

MWidgetModel * MWidgetController::model (  ) 

Returns the model of the widget.

This function will always return a valid model. The model should not be directly manipulated in the application code, unless the application also explicitly creates the model. Instead, the widget should provide the necessary functions in the controller class.

See also:
setModel()

Definition at line 144 of file mwidgetcontroller.cpp.

{
    return const_cast<MWidgetModel *>
           (static_cast<const MWidgetController &>(*this).model());
}

const MWidgetModel * MWidgetController::model (  )  const

Returns a const pointer to the model of the widget.

This function will always return a valid model.

See also:
setModel()

Definition at line 130 of file mwidgetcontroller.cpp.

{
    MWidgetControllerPrivate *d = (MWidgetControllerPrivate *)d_ptr;

    if (d->modelSetup == false) {
        // Clear the flag first to avoid recursion in case a derived setupModel calls model()
        d->modelSetup = true;
        const_cast<MWidgetController &>(*this).setupModel();
    }

    return d->model;
}

void MWidgetController::mouseMoveEvent ( QGraphicsSceneMouseEvent event  )  [protected, virtual]

MWidgetController's implementation of mouseMoveEvent() forwards the call to the view.

See also:
MWidgetView::mouseMoveEvent()

Definition at line 382 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    // check if we have, or if we can create a view
    if (view()) {
        // forward the event to the view
        translateMouseEvent(event, QPointF(d->view->marginLeft(), d->view->marginTop()));
        d->view->mouseMoveEvent(event);
    }
}

Here is the call graph for this function:

void MWidgetController::mousePressEvent ( QGraphicsSceneMouseEvent event  )  [protected, virtual]

MWidgetController's implementation of mousePressEvent() forwards the call to the view.

See also:
MWidgetView::mousePressEvent()

Definition at line 360 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    // check if we have, or if we can create a view
    if (view()) {
        // forward the event to the view
        translateMouseEvent(event, QPointF(d->view->marginLeft(), d->view->marginTop()));
        d->view->mousePressEvent(event);
    }
}

Here is the call graph for this function:

void MWidgetController::mouseReleaseEvent ( QGraphicsSceneMouseEvent event  )  [protected, virtual]

MWidgetController's implementation of mouseReleaseEvent() forwards the call to the view.

See also:
MWidgetView::mouseReleaseEvent()

Definition at line 371 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    // check if we have, or if we can create a view
    if (view()) {
        // forward the event to the view
        translateMouseEvent(event, QPointF(d->view->marginLeft(), d->view->marginTop()));
        d->view->mouseReleaseEvent(event);
    }
}

Here is the call graph for this function:

void MWidgetController::orientationChangeEvent ( MOrientationChangeEvent event  )  [protected, virtual]

MWidgetController's implementation of orientationChangeEvent() forwards the call to the view.

See also:
MWidgetView::orientationChangeEvent()

Reimplemented from MWidget.

Definition at line 401 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (view())
        d->view->orientationChangeEvent(event);
}

Here is the call graph for this function:

void MWidgetController::panGestureEvent ( QGestureEvent event,
QPanGesture gesture 
) [protected, virtual]

MWidgetController's implementation of panGestureEvent() forwards the call to the view.

See also:
MWidgetView::panGestureEvent()

Reimplemented from MWidget.

Definition at line 415 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    // We are using here a hack which will allow reimplementing the panGestureEvent
    // method in the pannable widget without recompilation of all client applications.
    // This needs to be deleted when API unfreeze will finally happen.
    if( MPannableWidget* pannableWidget = qobject_cast< MPannableWidget* >( this ))
        pannableWidget->MPannableWidget::panGestureEvent(event, gesture);
    else {
        if (view())
            d->view->panGestureEvent(event,gesture);
    }
}

Here is the call graph for this function:

void MWidgetController::pinchGestureEvent ( QGestureEvent event,
QPinchGesture gesture 
) [protected, virtual]

MWidgetController's implementation of pinchGestureEvent() forwards the call to the view.

See also:
MWidgetView::pinchGestureEvent()

Reimplemented from MWidget.

Definition at line 429 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (view())
        d->view->pinchGestureEvent(event,gesture);
}

Here is the call graph for this function:

bool MWidgetController::sceneEventFilter ( QGraphicsItem watched,
QEvent event 
) [protected, virtual]

MWidgetController's implementation of sceneEventFilter() forwards the call to the view.

See also:
MWidgetView::sceneEventFilter()

Definition at line 613 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    // check if we have, or if we can create a view
    if (view())
        return d->view->sceneEventFilter(watched, event);
    return false;
}

Here is the call graph for this function:

void MWidgetController::setActive ( bool  active  )  [virtual, slot]

Set the active state of the widget

Active state is communicated to the widget view and can affect how the widget is presented. By default widgets are inactive. What active state semantically means is up the individual widget.

See also:
isActive() MWidgetView::setActive()

Definition at line 471 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (d->active != targetState) {
        d->active = targetState;
        if (view())
            d->view->setActive(targetState);
    }
}

Here is the call graph for this function:

void MWidgetController::setLayoutPosition ( M::Position  layoutPosition  ) 

Definition at line 226 of file mwidgetcontroller.cpp.

{
    model()->setLayoutPosition(layoutPosition);
}

Here is the call graph for this function:

void MWidgetController::setModel ( MWidgetModel model  ) 

Sets the model of the widget.

This function will increase the reference count on the given model. If a model was already set prior to calling this function, that model's reference count will be decreased and the model destroyed if it reaches 0.

See also:
model()

Definition at line 186 of file mwidgetcontroller.cpp.

{
    Q_ASSERT_X(model, "MWidgetController", "MWidgetController::setModel() parameter model has to be valid!");
    Q_D(MWidgetController);
    d->setModel(model);
    //Call setupModel immediately since this is not called from the constructor
    setupModel();
}

Here is the call graph for this function:

void MWidgetController::setObjectName ( const QString name  )  [virtual, slot]

Set the objectName to name

This function sets the QObject::objectName property of the widget and reloads the style of the widget view. The object name is used by the theme system to select a style with a matching ID.

Warning: Since QObject::setObjectName() is non-virtual, code like:

       MLabel *label = new MLabel("Hello");
       label->setObjectName("hello");

Would correctly restyle the label. But:

       QGraphicsWidget *label = new MLabel("Hello");
       label->setObjectName("hello");

Would not update the CSS style correctly.

Note that multiple objects can have the same name, and consequently the same style.

Deprecated:
Use setStyleName() to set the style name of the widget.

Definition at line 515 of file mwidgetcontroller.cpp.

{
    MWidget::setObjectName(name);

    model()->setObjectName(name);
}

Here is the call graph for this function:

void MWidgetController::setStyleName ( const QString name  )  [slot]

Set the style name to name.

This function sets the style name property of the widget to name and reloads the style of the widget view. The style name is used to select a style with a matching name from the theme.

An example of setting the object name:

        mywidget->setStyleName("warning");

In a CSS file you can then specify a style for this particular widget:

        #warning { background-color: #FF0000; }
See also:
styleName()

Definition at line 522 of file mwidgetcontroller.cpp.

{
    model()->setStyleName(name);
}

Here is the call graph for this function:

void MWidgetController::setupModel (  )  [protected, virtual, slot]

Notification of model having changed.

This function is called when the model of the widget is initially set or when later replaced. You can reimplement this method to synchronize your widget's internal state with that of the new model.

An example would be an widget that creates a child label widget; on setupModel() it should synchronize the label text with the model data. Subsequent updates to the model data and the resulting changes to the label are delivered through updateData().

Note:
The widget uses the base implementation of this function to set up notification of changes in the model. Because of this, it is very important that subclasses call the base implementation.
See also:
setModel()
updateData()

Definition at line 170 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    d->modelSetup = true;
}

void MWidgetController::setView ( MWidgetView view  )  [virtual]

Sets the view of the widget.

See also:
view()

Definition at line 234 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);

    // check if we already had a view and destroy it.
    if (d->view != NULL)
        d->view->destroy();

    // set the new view
    d->view = view;

    // if the user gave us a view
    if (d->view) {
        // set the flag that user has manually set the view, so theme won't override it.
        d->viewSetManually = true;

        d->configureView(d->view);

        // TODO: check if this is really needed.
        prepareGeometryChange();
    } else {
        // user set a NULL view

        // unset the flag so now the view will be again controlled by the theme.
        d->viewSetManually = false;
    }
    updateGeometry();
}

Here is the call graph for this function:

void MWidgetController::setViewType ( const MTheme::ViewType type  )  [slot]

Set the view type of the widget.

The type determines which MWidgetView the theme system will select at runtime.

Example:

A button of the "toggle" type may for example look and behave like a checkbox or a slider, depending on the selected theme.

See also:
viewType()

Definition at line 487 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    d->viewSetManually = false;
    d->deprecateView();
    model()->setViewType(type);
}

Here is the call graph for this function:

const MWidgetStyleContainer & MWidgetController::style (  )  const [protected]

Returns a constant reference to the style of the widget.

Definition at line 627 of file mwidgetcontroller.cpp.

{
    return view()->style();
}

Here is the call graph for this function:

MWidgetStyleContainer & MWidgetController::style (  )  [protected]

Returns the style of the widget.

Reimplemented from QGraphicsWidget.

Definition at line 622 of file mwidgetcontroller.cpp.

{
    return const_cast<MWidgetStyleContainer &>(view()->style());
}

Here is the call graph for this function:

const QString& MWidgetController::styleName (  )  const

Returns the style name of the widget.

void MWidgetController::swipeGestureEvent ( QGestureEvent event,
QSwipeGesture gesture 
) [protected, virtual]

MWidgetController's implementation of swipeGestureEvent() forwards the call to the view.

See also:
MWidgetView::swipeGestureEvent()

Reimplemented from MWidget.

Definition at line 443 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (view())
        d->view->swipeGestureEvent(event,gesture);
}

Here is the call graph for this function:

void MWidgetController::tapAndHoldGestureEvent ( QGestureEvent event,
QTapAndHoldGesture gesture 
) [protected, virtual]

MWidgetController's implementation of tapAndHoldGestureEvent() forwards the call to the view.

See also:
MWidgetView::tapAndHoldGestureEvent()

Reimplemented from MWidget.

Definition at line 408 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (view())
        d->view->tapAndHoldGestureEvent(event,gesture);
}

Here is the call graph for this function:

void MWidgetController::tapGestureEvent ( QGestureEvent event,
QTapGesture gesture 
) [protected, virtual]

MWidgetController's implementation of tapGestureEvent() forwards the call to the view.

See also:
MWidgetView::tapGestureEvent()

Reimplemented from MWidget.

Definition at line 436 of file mwidgetcontroller.cpp.

{
    Q_D(MWidgetController);
    if (view())
        d->view->tapGestureEvent(event,gesture);
}

Here is the call graph for this function:

void MWidgetController::updateData ( const QList< const char * > &  modifications  )  [protected, virtual, slot]

Notification of model data modifications.

This function is called when some members of the widget model have been modified.

Reimplemented in MList, and MSlider.

Definition at line 164 of file mwidgetcontroller.cpp.

{
    Q_UNUSED(modifications);
}

void MWidgetController::updateMicroFocus (  )  [protected, slot]

Updates the widget's micro focus.

See also:
QWidget::updateMicroFocus.

Definition at line 176 of file mwidgetcontroller.cpp.

{
    QInputContext *ic = qApp->inputContext();

    if (ic != 0) {
        ic->update();
    }
}

Here is the call graph for this function:

const MWidgetView * MWidgetController::view (  )  const [protected]

Returns a constant pointer to the view of the widget.

See also:
setView()

Definition at line 151 of file mwidgetcontroller.cpp.

{
    Q_D(const MWidgetController);

    if (!d->view) {
        Q_ASSERT_X(d->model, "MWidgetController", "You should not call MWidgetController::view() before the widget has a model!");
        const_cast<MWidgetControllerPrivate *>(d)->createView();
    }

    return d->view;
}

MTheme::ViewType MWidgetController::viewType (  )  const

Returns the type of the widget's view.

See also:
setViewType()

Member Data Documentation

Default widget view type.

See also:
viewType(), setViewType()

Definition at line 65 of file corelib/widgets/core/mwidgetcontroller.h.


Property Documentation

bool MWidgetController::active [read, write]

Definition at line 56 of file corelib/widgets/core/mwidgetcontroller.h.

const QString & MWidgetController::styleName [read, write]

Definition at line 57 of file corelib/widgets/core/mwidgetcontroller.h.

MTheme::ViewType MWidgetController::viewType [read, write]

Definition at line 55 of file corelib/widgets/core/mwidgetcontroller.h.


Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:27 (PDT)
Doxygen 1.7.1
MeeGo Touch