You Are Here:

Community: Wiki

This page was last modified on 31 October 2009, at 15:52.

Mapping of StandardItemModel via DataWidgetMapper in Qt for Symbian

From Forum Nokia Wiki


ID ... Creation date 26 June 2009
Platform S60 3rd Edition, S60 5th Edition Tested on devices S60 Emulator
Category Qt for Symbian Subcategory UI


Keywords (APIs, classes, methods, functions): QStandardItemModel,QDataWidgetMapper

Overview

This will show you the mapping of the StandardItemModel to DataWidgetMapper and directly to QLineEdit.

QDataWidgetMapper can be used to create data-aware widgets by mapping them to sections of an item model. A section is a column of a model if the orientation is horizontal (the default), otherwise a row.

Preconditions


Source Code

Header File

#ifndef MODEL_H
#define MODEL_H
 
#include <QtGui/QWidget>
#include<QLabel>
#include<QLineEdit>
#include<QPushButton>
#include<QStandardItemModel>
#include<QStringListModel>
#include<QDataWidgetMapper>
#include<QGridLayout>
#include<QStandardItem>
#include<QStringList>
class model : public QWidget
{
Q_OBJECT
 
public:
model(QWidget *parent = 0);
~model();
 
private slots:
void updateButtons(int row);
 
private:
void virModel();
 
QLabel *nameLabel;
QLineEdit *nameEdit;
QPushButton *nextButton;
QPushButton *previousButton;
QStandardItemModel *modelversion;
QStringListModel *typeModel;
QDataWidgetMapper *mapper;
};
 
#endif // MODEL_H

Source File

#include "model.h"
model::model(QWidget *parent)
: QWidget(parent)
{
virModel();
 
nameLabel = new QLabel(tr("Na&me:"),this);
nameEdit = new QLineEdit(this);
nameLabel->setBuddy(nameEdit);
nextButton = new QPushButton(tr("&Next"),this);
previousButton = new QPushButton(tr("&Previous"),this);
mapper = new QDataWidgetMapper(this);
mapper->setModel(modelversion); //mapping of the dataModel is Done
mapper->addMapping(nameEdit,0);
connect(previousButton, SIGNAL(clicked()),mapper,SLOT(toPrevious()));
connect(nextButton, SIGNAL(clicked()),
mapper, SLOT(toNext()));
connect(mapper, SIGNAL(currentIndexChanged(int)),
this, SLOT(updateButtons(int)));
 
QGridLayout *layout = new QGridLayout(this); //Widget Layout is set
layout->addWidget(nameLabel, 0, 0, 1, 1);
layout->addWidget(nameEdit, 0, 1, 1, 1);
layout->addWidget(previousButton, 0, 2, 1, 1);
layout->addWidget(nextButton, 1, 2, 1, 1);
setLayout(layout);
setWindowTitle(tr("Widget Mapper"));
mapper->toFirst();
}
 
model::~model()
{
// No need to delete any object that has got a parent which is properly deleted.
}
void model::virModel() //Whole the stringlist items are added to standardItemModel
{
modelversion = new QStandardItemModel(5,1,this);
 
QStringList names;
names << "symbian" << "UIQ" << "ANDROID" << "NOKIA" << "APPLE";
 
for (int row = 0; row < 5; ++row)
{
QStandardItem *item = new QStandardItem(names[row]);
modelversion->setItem(row, 0, item);
}
 
 
}
void model::updateButtons(int row) //Module Execute when their is updation in QLineEdit
{
previousButton->setEnabled(row > 0);
nextButton->setEnabled(row < modelversion->rowCount() - 1);
}

Screenshot

Image:Widmapper.jpg


Related Links

Mapping signal via signalMapper

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fAE5ftourE5ftoE5ftheE5fE51tE5fE28E51tE5fforE5fSymbianE29X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZE71tQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxE71tX qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ