Modified components widget so the checked items can be stored for all pages to access
parent
77fe73799a
commit
30710bad70
@ -0,0 +1,46 @@
|
||||
#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);
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef COMPONENTLISTWIDGET_HPP
|
||||
#define COMPONENTLISTWIDGET_HPP
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
class ComponentListWidget : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QStringList mCheckedItems READ checkedItems)
|
||||
|
||||
public:
|
||||
ComponentListWidget(QWidget *parent = 0);
|
||||
|
||||
QStringList mCheckedItems;
|
||||
QStringList checkedItems();
|
||||
|
||||
void addItem(QListWidgetItem *item);
|
||||
|
||||
signals:
|
||||
void checkedItemsChanged(const QStringList &items);
|
||||
|
||||
private slots:
|
||||
void updateCheckedItems(QListWidgetItem *item);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // COMPONENTLISTWIDGET_HPP
|
Loading…
Reference in New Issue