Home · All Classes · Main Classes · Deprecated
Public Slots | Signals | Public Member Functions | Properties

MComboBox Class Reference

MComboBox implementation of a comboBox widget. More...

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

List of all members.

Public Slots

void clear ()
void setIconID (const QString &id)
void setIconVisible (bool)
void setTitle (const QString &title)
void setProgressIndicatorVisible (bool visible)
void showProgressIndicator ()
void hideProgressIndicator ()
void setCurrentIndex (int index)
void click ()
void dismiss ()

Signals

void clicked ()
void dismissed ()
void currentIndexChanged (int index)
void currentIndexChanged (const QString &text)
void activated (int index)
void activated (const QString &text)

Public Member Functions

 MComboBox (QGraphicsItem *parent=0)
virtual ~MComboBox ()
virtual void setItemModel (QAbstractItemModel *itemModel)
QAbstractItemModelitemModel () const
virtual void setSelectionModel (QItemSelectionModel *selectionModel)
QItemSelectionModelselectionModel () const
QString iconID () const
bool isIconVisible () const
QString title () const
bool isProgressIndicatorVisible () const
void addItem (const QString &text)
void addItem (const QString &iconID, const QString &text)
void addItems (const QStringList &texts)
int count () const
int currentIndex () const
QString currentText () const
QString itemText (int index) const
QString itemIconID (int index) const
void insertItem (int index, const QString &text)
void insertItem (int index, const QString &icon, const QString &text)
void insertItems (int index, const QStringList &list)
void removeItem (int index)
void setItemText (int index, const QString &text)
void setItemIconID (int index, const QString &iconID)

Properties

QString iconID
bool iconVisible
QString title
bool progressIndicatorVisible
QAbstractItemModel itemModel
QItemSelectionModel selectionModel
int currentIndex
QString currentText
int count

Detailed Description

MComboBox implementation of a comboBox widget.

Overview

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.


Constructor & Destructor Documentation

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.

{
    disconnect(model()->itemModel(), SIGNAL(destroyed()), this, SLOT(_q_modelDestroyed()));
}

Here is the call graph for this function:


Member Function Documentation

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

Here is the call graph for this function:

void MComboBox::addItem ( const QString iconID,
const QString 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);
}

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

void MComboBox::click (  )  [slot]

Performs a click.

Definition at line 379 of file mcombobox.cpp.

{
    emit clicked();
}

Here is the call graph for this function:

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

Here is the call graph for this function:

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.

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.

See also:
insertItems()

Definition at line 252 of file mcombobox.cpp.

{
    insertItem(index, QString(), text);
}

void MComboBox::insertItem ( int  index,
const QString icon,
const 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.

See also:
insertItems()

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

Here is the call graph for this function:

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.

See also:
insertItem()

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

Here is the call graph for this function:

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

Here is the call graph for this function:

bool MComboBox::isProgressIndicatorVisible (  )  const

Returns true if progress indicator is visible.

Definition at line 186 of file mcombobox.cpp.

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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.

  • itemModel The model to use as a new datasource

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

Here is the call graph for this function:

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

Here is the call graph for this function:

void MComboBox::setProgressIndicatorVisible ( bool  visible  )  [slot]

shows progress indicator

Definition at line 359 of file mcombobox.cpp.

{
    model()->setProgressIndicatorVisible(enable);
}

Here is the call graph for this function:

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.

Note:
It is up to the application to delete the old selection model if it is no longer needed; i.e., if it is not being used by other views. This will happen automatically when its parent object is deleted. However, if it does not have a parent, or if the parent is a long-lived object, it may be preferable to call its deleteLater() function to explicitly delete it.
See also:
selectionModel(), setItemModel()

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

Here is the call graph for this function:

void MComboBox::setTitle ( const QString title  )  [slot]

Set comboBox title.

Definition at line 354 of file mcombobox.cpp.

{
    model()->setTitle(title);
}

Here is the call graph for this function:

void MComboBox::showProgressIndicator (  )  [inline, slot]

shows progress indicator

Definition at line 351 of file corelib/widgets/mcombobox.h.

QString MComboBox::title (  )  const

Returns the title of comboBox.


Property Documentation

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]

See MComboBoxModel::iconID.

Definition at line 82 of file corelib/widgets/mcombobox.h.

MComboBox::iconVisible [read, write]
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]
MComboBox::selectionModel [read, write]

Keeps track of itemModel selected items.

Definition at line 112 of file corelib/widgets/mcombobox.h.

MComboBox::title [read, write]

See MComboBoxModel::title.

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