mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
|
#include "componentlistwidget.hpp"
|
||
|
|
||
|
#include <QDebug>
|
||
|
#include <QStringList>
|
||
|
|
||
|
ComponentListWidget::ComponentListWidget(QWidget *parent) :
|
||
|
QListWidget(parent)
|
||
|
{
|
||
|
mCheckedItems = QStringList();
|
||
|
|
||
|
connect(this, SIGNAL(itemChanged(QListWidgetItem *)),
|
||
|
this, SLOT(updateCheckedItems(QListWidgetItem *)));
|
||
|
}
|
||
|
|
||
|
void ComponentListWidget::addItem(QListWidgetItem *item)
|
||
|
{
|
||
|
// The model does not emit a dataChanged signal when items are added
|
||
|
// So we need to update manually
|
||
|
QListWidget::insertItem(count(), item);
|
||
|
updateCheckedItems(item);
|
||
|
|
||
|
}
|
||
|
|
||
|
QStringList ComponentListWidget::checkedItems()
|
||
|
{
|
||
|
mCheckedItems.removeDuplicates();
|
||
|
return mCheckedItems;
|
||
|
}
|
||
|
|
||
|
void ComponentListWidget::updateCheckedItems(QListWidgetItem *item)
|
||
|
{
|
||
|
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);
|
||
|
|
||
|
}
|