You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw/apps/wizard/utils/componentlistwidget.cpp

48 lines
1.1 KiB
C++

#include "componentlistwidget.hpp"
ComponentListWidget::ComponentListWidget(QWidget* parent)
: QListWidget(parent)
{
mCheckedItems = QStringList();
connect(this, &ComponentListWidget::itemChanged, this,
qOverload<QListWidgetItem*>(&ComponentListWidget::updateCheckedItems));
connect(model(), &QAbstractItemModel::rowsInserted, this,
qOverload<const QModelIndex&, int, int>(&ComponentListWidget::updateCheckedItems));
}
QStringList ComponentListWidget::checkedItems()
{
mCheckedItems.removeDuplicates();
return mCheckedItems;
}
void ComponentListWidget::updateCheckedItems(const QModelIndex& index, int start, int end)
{
updateCheckedItems(item(start));
}
void ComponentListWidget::updateCheckedItems(QListWidgetItem* item)
{
if (!item)
return;
QString text = item->text();
if (item->checkState() == Qt::Checked)
{
if (!mCheckedItems.contains(text))
mCheckedItems.append(text);
}
else
{
if (mCheckedItems.contains(text))
mCheckedItems.removeAll(text);
}
mCheckedItems.removeDuplicates();
emit checkedItemsChanged(mCheckedItems);
}