| Home · All Classes · Main Classes · Deprecated |
MWidgetController is the base class for a controller in the MVC widget model. More...


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.
| 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);
}

| 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);
}

| 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);
}

| void MWidgetController::cancelEvent | ( | MCancelEvent * | event | ) | [protected, virtual] |
MWidgetController's implementation of cancelEvent() forwards the call to the view.
Reimplemented from MWidget.
Definition at line 393 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
if (view()) {
d->view->cancelEvent(event);
}
}

| QVariant MWidgetController::inputMethodQuery | ( | Qt::InputMethodQuery | query | ) | const [protected, virtual] |
MWidgetController's implementation of inputMethodQuery() forwards the call to the view.
Definition at line 461 of file mwidgetcontroller.cpp.
{
Q_D(const MWidgetController);
if (view()) {
return d->view->inputMethodQuery(query);
} else {
return QVariant();
}
}

| bool MWidgetController::isActive | ( | ) | const |
Indicates whether this widget is an active state.
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.
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();
}

| 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.
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.
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.
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);
}
}

| void MWidgetController::mousePressEvent | ( | QGraphicsSceneMouseEvent * | event | ) | [protected, virtual] |
MWidgetController's implementation of mousePressEvent() forwards the call to the view.
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);
}
}

| void MWidgetController::mouseReleaseEvent | ( | QGraphicsSceneMouseEvent * | event | ) | [protected, virtual] |
MWidgetController's implementation of mouseReleaseEvent() forwards the call to the view.
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);
}
}

| void MWidgetController::orientationChangeEvent | ( | MOrientationChangeEvent * | event | ) | [protected, virtual] |
MWidgetController's implementation of orientationChangeEvent() forwards the call to the view.
Reimplemented from MWidget.
Definition at line 401 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
if (view())
d->view->orientationChangeEvent(event);
}

| void MWidgetController::panGestureEvent | ( | QGestureEvent * | event, | |
| QPanGesture * | gesture | |||
| ) | [protected, virtual] |
MWidgetController's implementation of panGestureEvent() forwards the call to the view.
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);
}
}

| void MWidgetController::pinchGestureEvent | ( | QGestureEvent * | event, | |
| QPinchGesture * | gesture | |||
| ) | [protected, virtual] |
MWidgetController's implementation of pinchGestureEvent() forwards the call to the view.
Reimplemented from MWidget.
Definition at line 429 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
if (view())
d->view->pinchGestureEvent(event,gesture);
}

| bool MWidgetController::sceneEventFilter | ( | QGraphicsItem * | watched, | |
| QEvent * | event | |||
| ) | [protected, virtual] |
MWidgetController's implementation of sceneEventFilter() forwards the call to the view.
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;
}

| 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.
Definition at line 471 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
if (d->active != targetState) {
d->active = targetState;
if (view())
d->view->setActive(targetState);
}
}

| void MWidgetController::setLayoutPosition | ( | M::Position | layoutPosition | ) |
Definition at line 226 of file mwidgetcontroller.cpp.
{
model()->setLayoutPosition(layoutPosition);
}

| 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.
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();
}

| 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.
Definition at line 515 of file mwidgetcontroller.cpp.
{
MWidget::setObjectName(name);
model()->setObjectName(name);
}

| 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; }
Definition at line 522 of file mwidgetcontroller.cpp.
{
model()->setStyleName(name);
}

| 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().
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.
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();
}

| 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:
MButton button; button.setViewType(MButton::toggleType);
A button of the "toggle" type may for example look and behave like a checkbox or a slider, depending on the selected theme.
Definition at line 487 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
d->viewSetManually = false;
d->deprecateView();
model()->setViewType(type);
}

| const MWidgetStyleContainer & MWidgetController::style | ( | ) | const [protected] |
Returns a constant reference to the style of the widget.
Definition at line 627 of file mwidgetcontroller.cpp.

| 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());
}

| 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.
Reimplemented from MWidget.
Definition at line 443 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
if (view())
d->view->swipeGestureEvent(event,gesture);
}

| void MWidgetController::tapAndHoldGestureEvent | ( | QGestureEvent * | event, | |
| QTapAndHoldGesture * | gesture | |||
| ) | [protected, virtual] |
MWidgetController's implementation of tapAndHoldGestureEvent() forwards the call to the view.
Reimplemented from MWidget.
Definition at line 408 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
if (view())
d->view->tapAndHoldGestureEvent(event,gesture);
}

| void MWidgetController::tapGestureEvent | ( | QGestureEvent * | event, | |
| QTapGesture * | gesture | |||
| ) | [protected, virtual] |
MWidgetController's implementation of tapGestureEvent() forwards the call to the view.
Reimplemented from MWidget.
Definition at line 436 of file mwidgetcontroller.cpp.
{
Q_D(MWidgetController);
if (view())
d->view->tapGestureEvent(event,gesture);
}

| 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.
Definition at line 176 of file mwidgetcontroller.cpp.
{
QInputContext *ic = qApp->inputContext();
if (ic != 0) {
ic->update();
}
}

| const MWidgetView * MWidgetController::view | ( | ) | const [protected] |
Returns a constant pointer to the view of the widget.
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.
const MTheme::ViewType MWidgetController::defaultType = "default" [static] |
Default widget view type.
Definition at line 65 of file corelib/widgets/core/mwidgetcontroller.h.
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 |