void QxtCheckComboBox::updateCheckedItems() { QStringList items = checkedItems(); if (items.isEmpty()) setEditText(m_defaultText); else { if(m_displayMultipleSelection || items.size() == 1) setEditText(items.join(m_separator)); else setEditText(m_multipleSelectionText.arg(items.size())); } emit checkedItemsChanged(items); }
bool DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid()) return false; if (role == Qt::CheckStateRole) { emit layoutAboutToBeChanged(); QString name = item(index.row())->fileName(); mCheckStates[name] = static_cast<Qt::CheckState>(value.toInt()); emit checkedItemsChanged(checkedItems(), uncheckedItems()); emit layoutChanged(); return true; } return false; }
QStringList DataFilesModel::uncheckedItems() { QStringList list; QStringList checked = checkedItems(); QList<EsmFile *>::ConstIterator it; QList<EsmFile *>::ConstIterator itEnd = mFiles.constEnd(); int i = 0; for (it = mFiles.constBegin(); it != itEnd; ++it) { EsmFile *file = item(i); ++i; // Add the items that are not in the checked list if (!checked.contains(file->fileName())) list << file->fileName(); } return list; }
bool DataFilesModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (!index.isValid()) return false; if (role == Qt::CheckStateRole) { QString name = item(index.row())->fileName(); mCheckStates[name] = static_cast<Qt::CheckState>(value.toInt()); // Force a redraw of the view since unchecking one item can affect another QModelIndex firstIndex = indexFromItem(mFiles.first()); QModelIndex lastIndex = indexFromItem(mFiles.last()); emit dataChanged(firstIndex, lastIndex); emit checkedItemsChanged(checkedItems()); return true; } return false; }