ComponentModel Class

(QInstaller::ComponentModel)

The ComponentModel class holds a data model for visual representation of available components to install. More...

Header: #include <ComponentModel>

Public Types

flags ModelState
enum ModelStateFlag { AllChecked, AllUnchecked, DefaultChecked, PartiallyChecked }

Public Functions

ComponentModel(int columns, PackageManagerCore *core = 0)
~ComponentModel()
QSet<Component *> checked() const
ComponentModel::ModelState checkedState() const
int columnCount(const QModelIndex &parent = QModelIndex()) const
Component *componentFromIndex(const QModelIndex &index) const
PackageManagerCore *core() const
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
Qt::ItemFlags flags(const QModelIndex &index) const
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
QModelIndex indexFromComponentName(const QString &name) const
QModelIndex parent(const QModelIndex &child) const
QSet<Component *> partially() const
int rowCount(const QModelIndex &parent = QModelIndex()) const
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)
QSet<Component *> uncheckable() const
QSet<Component *> unchecked() const

Public Slots

void setCheckedState(QInstaller::ComponentModel::ModelStateFlag state)
void setRootComponents(QList<QInstaller::Component *> rootComponents)

Signals

void checkStateChanged(const QModelIndex &index)
void checkStateChanged(QInstaller::ComponentModel::ModelState state)

Detailed Description

The ComponentModel class holds a data model for visual representation of available components to install.

Member Type Documentation

enum ComponentModel::ModelStateFlag
flags ComponentModel::ModelState

This enum value holds the checked state of the components available for installation.

ConstantValueDescription
QInstaller::ComponentModel::AllChecked0x01All components are checked.
QInstaller::ComponentModel::AllUnchecked0x02No components are checked.
QInstaller::ComponentModel::DefaultChecked0x04The components to be installed by default are checked.
QInstaller::ComponentModel::PartiallyChecked0x08Some components are checked.

The ModelState type is a typedef for QFlags<ModelStateFlag>. It stores an OR combination of ModelStateFlag values.

Member Function Documentation

ComponentModel::ComponentModel(int columns, PackageManagerCore *core = 0)

Constructs a component model with the given number of columns and core as parent.

ComponentModel::~ComponentModel()

Destroys the component model.

[signal] void ComponentModel::checkStateChanged(const QModelIndex &index)

This signal is emitted whenever the checked state of a component is changed. The index value indicates the QModelIndex representation of the component as seen from the model.

Note:Signal checkStateChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(componentModel, static_cast<void(ComponentModel::*)(const QModelIndex &)>(&ComponentModel::checkStateChanged),
      [=](const QModelIndex &index){ /* ... */ });

[signal] void ComponentModel::checkStateChanged(QInstaller::ComponentModel::ModelState state)

This signal is emitted whenever the checked state of a model is changed after all state calculations have taken place. The state is a combination of ModelStateFlag values indicating whether the model has its default checked state, all components are checked or unchecked, or some individual component's checked state has changed.

Note:Signal checkStateChanged is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:


  connect(componentModel, static_cast<void(ComponentModel::*)(QInstaller::ComponentModel::ModelState)>(&ComponentModel::checkStateChanged),
      [=](QInstaller::ComponentModel::ModelState state){ /* ... */ });

QSet<Component *> ComponentModel::checked() const

Returns a list of checked components.

ComponentModel::ModelState ComponentModel::checkedState() const

Returns the current checked state of the model.

See also setCheckedState().

int ComponentModel::columnCount(const QModelIndex &parent = QModelIndex()) const

Returns the number of columns of the given parent.

Component *ComponentModel::componentFromIndex(const QModelIndex &index) const

Translates between a given QModelIndex index and its associated Component. Returns the component if the index is valid or 0 if an invalid QModelIndex is given.

PackageManagerCore *ComponentModel::core() const

Returns a pointer to the PackageManagerCore this model belongs to.

QVariant ComponentModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const

Returns the data stored under the given role for the item referred to by the index.

Note: An invalid QVariant is returned if the given index is invalid. Qt::CheckStateRole is only supported for the first column of the model. Qt::EditRole, Qt::DisplayRole and Qt::ToolTipRole are specifically handled for columns greater than the first column and translate to Qt::UserRole + index.column().

See also setData().

Qt::ItemFlags ComponentModel::flags(const QModelIndex &index) const

Returns the item flags for the given index.

Returns a combination of flags that enables the item (Qt::ItemIsEnabled) and allows it to be selected (Qt::ItemIsSelectable) and to be checked (Qt::ItemIsUserCheckable).

QVariant ComponentModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const

Returns the data for the given role and section in the header with the specified orientation. An invalid QVariant is returned if section is out of bounds, orientation is not Qt::Horizontal or role is anything else than Qt::DisplayRole.

See also setHeaderData().

QModelIndex ComponentModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const

Returns the index of the item in the model specified by the given row, column, and parent index.

QModelIndex ComponentModel::indexFromComponentName(const QString &name) const

Translates between a given component name and its associated QModelIndex. Returns the QModelIndex that represents the component or an invalid QModelIndex if the component does not exist in the model.

QModelIndex ComponentModel::parent(const QModelIndex &child) const

Returns the parent item of the given child. If the item has no parent, an invalid QModelIndex is returned.

QSet<Component *> ComponentModel::partially() const

Returns a list of partially checked components.

int ComponentModel::rowCount(const QModelIndex &parent = QModelIndex()) const

Returns the number of items under the given parent. When the parent index is invalid, the returned value is the root item count.

[slot] void ComponentModel::setCheckedState(QInstaller::ComponentModel::ModelStateFlag state)

Sets the checked state of every component in the model to be state.

The ComponentModel::PartiallyChecked flag is ignored by this function. Note that components are not changed if they are not checkable. The dataChanged() and checkStateChanged() signals are emitted.

See also checkedState().

bool ComponentModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)

Sets the role data for the item at index to value. Returns true if successful; otherwise returns false. The dataChanged() signal is emitted if the data was successfully set. The checkStateChanged() signals are emitted in addition if the checked state of the item is set.

See also data().

bool ComponentModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)

Sets the data for the given role and section in the header with the specified orientation to the value supplied. Returns true if the header's data was updated; otherwise returns false. The headerDataChanged() signal is emitted if the data was successfully set.

Note: Only Qt::Horizontal orientation is supported.

See also headerData().

[slot] void ComponentModel::setRootComponents(QList<QInstaller::Component *> rootComponents)

Sets rootComponents to be the list of currently shown components.

The model is repopulated and the individual component's checked state is used to show the check mark in front of the visual component representation. The modelAboutToBeReset() and modelReset() signals are emitted.

QSet<Component *> ComponentModel::uncheckable() const

Returns a list of components whose checked state cannot be changed. If package manager core is run with no forced installation argument, the list will always be empty.

QSet<Component *> ComponentModel::unchecked() const

Returns a list of unchecked components.