| Home · All Classes · Main Classes · Deprecated |
MComboBox implementation of a comboBox widget. More...


MComboBox implementation of a comboBox widget.
The MComboBox widget is a combined button and popup list. It is very similar to QComboBox, but does not allow editing the text.
Currently, we expect the model to have only one level of depth, e.g. a table or list and not a tree model. Qt's QComboBox can handle trees by setting a root index but because writing tree models is more complex and showing a sublist is a rather rare use case, API is kept simple and expects simple models.
MComboBox uses the Qt's model/view framework for its popup list and to store its items. By default a QStandardItemModel stores the items and a MPopupList displays the popuplist. You can access the model by model(), but MComboBox also provides functions to set and get item data (e.g., setItemText() and itemText()). You can also set a new model.
A combobox can be populated using the insert functions, insertItem(), insertItems(), addItem() and addItems() for example. Items can be changed with setItemText(). An item can be removed with removeItem() and all items can be removed with clear(). The text of the current item is returned by currentText(), and the text of a numbered item is returned with itemText(). The current item can be set with setCurrentIndex(). The number of items in the combobox is returned by count();
For example, if you just want the user to pick from a list of strings:
MComboBox *combobox = new MComboBox(); combobox->setTitle("Select an item"); combobox->setIconID("icon-l-gallery"); QStringList stringList; stringList << "Item 1" << "Item 2"; combobox->addItems(stringList);
Definition at line 72 of file corelib/widgets/mcombobox.h.
| MComboBox::MComboBox | ( | QGraphicsItem * | parent = 0 |
) |
Constructs a combobox with the given parent.
Definition at line 91 of file mcombobox.cpp.
: MWidgetController(new MComboBoxPrivate(), new MComboBoxModel(), parent) { Q_D(MComboBox); d->init(); }
| MComboBox::~MComboBox | ( | ) | [virtual] |
Destroys the combobox.
Definition at line 105 of file mcombobox.cpp.

| void MComboBox::activated | ( | int | index | ) | [signal] |
This signal is sent when the user chooses an item in the combobox.
The item's index is passed.
Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged().
| void MComboBox::activated | ( | const QString & | text | ) | [signal] |
This signal is sent when the user chooses an item in the combobox.
The item's text is passed.
Note that this signal is sent even when the choice is not changed. If you need to know when the choice actually changes, use signal currentIndexChanged().
| void MComboBox::addItem | ( | const QString & | text | ) |
Adds an item to the combobox with the given text.
The item is appended to the list of existing items.
Definition at line 191 of file mcombobox.cpp.
{
insertItem(count(), text);
}

Adds an item to the combobox with the given iconID and text.
The item is appended to the list of existing items.
Definition at line 196 of file mcombobox.cpp.
{
insertItem(count(), iconID, text);
}

| void MComboBox::addItems | ( | const QStringList & | texts | ) |
Adds each of the strings in the given texts to the combobox.
Each item is appended to the list of existing items in turn.
Definition at line 201 of file mcombobox.cpp.
{
insertItems(count(), texts);
}

| void MComboBox::clear | ( | ) | [slot] |
Clears the combobox, removing all items.
Note: If you have set an external model on the combobox this model will still be cleared when calling this function.
Definition at line 338 of file mcombobox.cpp.
{
QAbstractItemModel *itemModel = model()->itemModel();
itemModel->removeRows(0, itemModel->rowCount());
}

| void MComboBox::click | ( | ) | [slot] |
Performs a click.
Definition at line 379 of file mcombobox.cpp.
{
emit clicked();
}

| void MComboBox::clicked | ( | ) | [signal] |
This signal is emitted when comboBox is clicked.
| int MComboBox::count | ( | ) | const |
the number of items in the combobox By default, for an empty combo box, this property has a value of 0.
| int MComboBox::currentIndex | ( | ) | const |
the index of the current item in the combobox.
The current index can change when inserting or removing items.
By default, for an empty combo box or a combo box in which no current item is set, this property has a value of -1.
| void MComboBox::currentIndexChanged | ( | int | index | ) | [signal] |
This signal is emitted whenever the currentIndex in the combobox changes either through user interaction or programmatically.
| void MComboBox::currentIndexChanged | ( | const QString & | text | ) | [signal] |
This is an overloaded member function, provided for convenience.
This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's text is passed.
| QString MComboBox::currentText | ( | ) | const |
the text of the current item
By default, for an empty combo box or a combo box in which no current item is set, this property contains an empty string.
| void MComboBox::dismiss | ( | ) | [slot] |
Dismisses popup list programatically.
Definition at line 384 of file mcombobox.cpp.
{
emit dismissed();
}

| void MComboBox::dismissed | ( | ) | [signal] |
This signal is emitted when popup list is dismissed.
| void MComboBox::hideProgressIndicator | ( | ) | [inline, slot] |
hides progress indicator
Definition at line 357 of file corelib/widgets/mcombobox.h.
{
setProgressIndicatorVisible(false);
}
| QString MComboBox::iconID | ( | ) | const |
Returns the logical ID associated with this comboBox's icon.
| void MComboBox::insertItem | ( | int | index, | |
| const QString & | text | |||
| ) |
Inserts the text into the combobox at the given index.
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
Definition at line 252 of file mcombobox.cpp.
{
insertItem(index, QString(), text);
}
Inserts the icon, text into the combobox at the given index.
If the index is equal to or higher than the total number of items, the new item is appended to the list of existing items. If the index is zero or negative, the new item is prepended to the list of existing items.
Definition at line 257 of file mcombobox.cpp.
{
int itemCount = count();
index = qBound(0, index, itemCount);
// For the common case where we are using the built in QStandardItemModel
// construct a QStandardItem, reducing the number of expensive signals from the model
QAbstractItemModel *itemModel = model()->itemModel();
if (QStandardItemModel *m = qobject_cast<QStandardItemModel *>(itemModel)) {
QStandardItem *item = new QStandardItem(text);
if (!iconID.isNull()) item->setData(iconID, Qt::DecorationRole);
m->insertRow(index, item);
} else {
if (itemModel->insertRows(index, 1)) {
QModelIndex item = itemModel->index(index, 0);
itemModel->setData(item, text, Qt::DisplayRole);
if (!iconID.isEmpty())
itemModel->setData(item, iconID, Qt::DecorationRole);
}
}
}

| void MComboBox::insertItems | ( | int | index, | |
| const QStringList & | list | |||
| ) |
Inserts the strings from the list into the combobox as separate items, starting at the index specified.
If the index is equal to or higher than the total number of items, the new items are appended to the list of existing items. If the index is zero or negative, the new items are prepended to the list of existing items.
Definition at line 281 of file mcombobox.cpp.
{
if (list.isEmpty())
return;
index = qBound(0, index, count());
int insertCount = list.count();
// For the common case where we are using the built in QStandardItemModel
// construct a QStandardItem, reducing the number of expensive signals from the model
QAbstractItemModel *itemModel = model()->itemModel();
if (QStandardItemModel *m = qobject_cast<QStandardItemModel *>(itemModel)) {
QList<QStandardItem *> items;
QStandardItem *hiddenRoot = m->invisibleRootItem();
for (int i = 0; i < insertCount; ++i)
items.append(new QStandardItem(list.at(i)));
hiddenRoot->insertRows(index, items);
} else {
if (itemModel->insertRows(index, insertCount)) {
QModelIndex item;
for (int i = 0; i < insertCount; ++i) {
item = itemModel->index(i + index, 0);
itemModel->setData(item, list.at(i), Qt::DisplayRole);
}
}
}
}

| bool MComboBox::isIconVisible | ( | ) | const |
Returns true if the icon of the comboBox is visible.
Definition at line 176 of file mcombobox.cpp.
{
return model()->iconVisible();
}

| bool MComboBox::isProgressIndicatorVisible | ( | ) | const |
Returns true if progress indicator is visible.
Definition at line 186 of file mcombobox.cpp.
{
return model()->progressIndicatorVisible();
}

| QString MComboBox::itemIconID | ( | int | index | ) | const |
Returns the iconID for the given index in the combobox.
Definition at line 241 of file mcombobox.cpp.
{
QAbstractItemModel *itemModel = model()->itemModel();
QModelIndex mi = itemModel->index(index, 0);
if (mi.isValid())
return itemModel->data(mi, Qt::DecorationRole).toString();
else
return QString();
}

| QAbstractItemModel* MComboBox::itemModel | ( | ) | const |
Returns the model that this comboBox is presenting.
| QString MComboBox::itemText | ( | int | index | ) | const |
Returns the text for the given index in the combobox.
Definition at line 230 of file mcombobox.cpp.
{
QAbstractItemModel *itemModel = model()->itemModel();
QModelIndex mi = itemModel->index(index, 0);
if (mi.isValid())
return itemModel->data(mi, Qt::DisplayRole).toString();
else
return QString();
}

| void MComboBox::removeItem | ( | int | index | ) |
Removes the item at the given index from the combobox.
This will update the current index if the index is removed.
Definition at line 312 of file mcombobox.cpp.
{
if (index >= 0 && index < count()) {
QAbstractItemModel *itemModel = model()->itemModel();
itemModel->removeRows(index, 1);
}
}

| QItemSelectionModel* MComboBox::selectionModel | ( | ) | const |
Returns the current selection model.
| void MComboBox::setCurrentIndex | ( | int | index | ) | [slot] |
Set current index.
Definition at line 364 of file mcombobox.cpp.
{
if (index == currentIndex()) return;
QItemSelectionModel *itemSelectionModel = model()->selectionModel();
if (itemSelectionModel == 0) return;
QModelIndex item = model()->itemModel()->index(index, 0);
if (item.isValid())
itemSelectionModel->setCurrentIndex(item, QItemSelectionModel::ClearAndSelect);
else
itemSelectionModel->clear();
}

| void MComboBox::setIconID | ( | const QString & | id | ) | [slot] |
Sets the logical ID associated with this comboBox's icon to id.
Definition at line 344 of file mcombobox.cpp.
{
model()->setIconID(id);
}

| void MComboBox::setIconVisible | ( | bool | visible | ) | [slot] |
Set the visibility of the icon of the comboBox.
Definition at line 349 of file mcombobox.cpp.
{
model()->setIconVisible(visible);
}

| void MComboBox::setItemIconID | ( | int | index, | |
| const QString & | iconID | |||
| ) |
Sets the iconID for the item on the given index in the combobox.
Definition at line 329 of file mcombobox.cpp.
{
QAbstractItemModel *itemModel = model()->itemModel();
QModelIndex item = itemModel->index(index, 0);
if (item.isValid()) {
itemModel->setData(item, iconID, Qt::DecorationRole);
}
}

| void MComboBox::setItemModel | ( | QAbstractItemModel * | itemModel | ) | [virtual] |
Sets the item model itemModel as the new datasource for the comboBox.
itemModel must not be 0.
MComboBox does not take ownership of the model. It is up the caller to ensure that it will be deleted. If the model is replaced, it is up to the caller to ensure the previous model is not leaked.
Definition at line 110 of file mcombobox.cpp.
{
QAbstractItemModel *oldModel = model()->itemModel();
if (itemModel == NULL || oldModel == itemModel)
return;
QItemSelectionModel *oldSelModel = model()->selectionModel();
if (oldSelModel)
oldSelModel->clear();
if (oldModel) {
disconnect(oldModel, SIGNAL(destroyed()), this, SLOT(_q_modelDestroyed()));
disconnect(oldModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(_q_itemModelDataChanged(QModelIndex, QModelIndex)));
disconnect(oldModel, SIGNAL(modelReset()), this, SLOT(_q_itemModelReset()));
}
QItemSelectionModel *itemSelectionModel = new QItemSelectionModel(itemModel, this);
model()->setItemModel(itemModel);
model()->setSelectionModel(itemSelectionModel);
if (oldSelModel && oldSelModel->QObject::parent() == this)
delete oldSelModel;
if (oldModel && oldModel->QObject::parent() == this)
delete oldModel;
connect(itemModel, SIGNAL(destroyed()), this, SLOT(_q_modelDestroyed()));
connect(itemModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(_q_itemModelDataChanged(QModelIndex, QModelIndex)));
connect(itemModel, SIGNAL(modelReset()), this, SLOT(_q_itemModelReset()));
connect(itemSelectionModel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(_q_selectionModelSelectionChanged(QItemSelection, QItemSelection)));
}

| void MComboBox::setItemText | ( | int | index, | |
| const QString & | text | |||
| ) |
Sets the text for the item on the given index in the combobox.
Definition at line 320 of file mcombobox.cpp.
{
QAbstractItemModel *itemModel = model()->itemModel();
QModelIndex item = itemModel->index(index, 0);
if (item.isValid()) {
itemModel->setData(item, text, Qt::DisplayRole);
}
}

| void MComboBox::setProgressIndicatorVisible | ( | bool | visible | ) | [slot] |
shows progress indicator
Definition at line 359 of file mcombobox.cpp.
{
model()->setProgressIndicatorVisible(enable);
}

| void MComboBox::setSelectionModel | ( | QItemSelectionModel * | selectionModel | ) | [virtual] |
Sets the current selection model to the given selectionModel.
Note that, if you call setItemModel() after this function, the given selectionModel will be replaced.
Definition at line 153 of file mcombobox.cpp.
{
if (selectionModel == NULL) return;
if (selectionModel->model() != itemModel()) {
qWarning("MComboBox::setSelectionModel() failed: "
"Trying to set a selection model, which works on "
"a different model than the view.");
return;
}
model()->setSelectionModel(selectionModel);
}

| void MComboBox::setTitle | ( | const QString & | title | ) | [slot] |
Set comboBox title.
Definition at line 354 of file mcombobox.cpp.
{
model()->setTitle(title);
}

| void MComboBox::showProgressIndicator | ( | ) | [inline, slot] |
shows progress indicator
Definition at line 351 of file corelib/widgets/mcombobox.h.
{
setProgressIndicatorVisible(true);
}
| QString MComboBox::title | ( | ) | const |
Returns the title of comboBox.
MComboBox::count [read] |
The number of items in the combobox.
By default, for an empty combo box, this property has the value of 0.
Definition at line 140 of file corelib/widgets/mcombobox.h.
MComboBox::currentIndex [read, write] |
The index of the current item in the combobox.
The current index can change when inserting or removing items.
By default, for an empty combo box or a combo box in which no current item is set, this property has the value of -1.
Definition at line 123 of file corelib/widgets/mcombobox.h.
MComboBox::currentText [read] |
The text of the current item.
By default, for an empty combo box or a combo box in which no current item is set, this property contains the empty string.
Definition at line 132 of file corelib/widgets/mcombobox.h.
MComboBox::iconID [read, write] |
Definition at line 82 of file corelib/widgets/mcombobox.h.
MComboBox::iconVisible [read, write] |
See MComboBoxModel::iconVisible.
Definition at line 88 of file corelib/widgets/mcombobox.h.
MComboBox::itemModel [read, write] |
The QAbstractItemModel which is used by the MComboBox for the list of items.
Definition at line 106 of file corelib/widgets/mcombobox.h.
MComboBox::progressIndicatorVisible [read, write] |
See MComboBoxModel::progressIndicatorVisible.
Definition at line 100 of file corelib/widgets/mcombobox.h.
MComboBox::selectionModel [read, write] |
Keeps track of itemModel selected items.
Definition at line 112 of file corelib/widgets/mcombobox.h.
MComboBox::title [read, write] |
Definition at line 94 of file corelib/widgets/mcombobox.h.
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:14:24 (PDT) Doxygen 1.7.1 |
MeeGo Touch |