|
|
|
@ -24,6 +24,7 @@ public:
|
|
|
|
|
:ITableModel(parent)
|
|
|
|
|
{
|
|
|
|
|
filtered = false;
|
|
|
|
|
m_checkboxSelect = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual ~AutoTableModel() {}
|
|
|
|
@ -50,6 +51,21 @@ public:
|
|
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (index.column() == 0 && m_checkboxSelect)
|
|
|
|
|
{
|
|
|
|
|
if (role == Qt::CheckStateRole)
|
|
|
|
|
{
|
|
|
|
|
if (m_selectedRows.contains(index.row()))
|
|
|
|
|
{
|
|
|
|
|
return Qt::Checked;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Qt::Unchecked;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSharedPointer<T> entity = m_list.at(index.row());
|
|
|
|
|
QObject *rawEntity = (QObject*)entity.data();
|
|
|
|
|
|
|
|
|
@ -189,6 +205,21 @@ public:
|
|
|
|
|
m_translations = translations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<int> selectedRows() const
|
|
|
|
|
{
|
|
|
|
|
return m_selectedRows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QSharedPointer<T> > selectedItems()
|
|
|
|
|
{
|
|
|
|
|
QList<QSharedPointer<T> > ret;
|
|
|
|
|
foreach (int row, m_selectedRows) {
|
|
|
|
|
ret.append(m_list[row]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void handleFilter(const QString &filter) override
|
|
|
|
|
{
|
|
|
|
@ -220,10 +251,10 @@ protected:
|
|
|
|
|
private:
|
|
|
|
|
QList<QSharedPointer<T> > m_list;
|
|
|
|
|
QList<QSharedPointer<T> > m_fullList;
|
|
|
|
|
QList<int> m_selectedRows;
|
|
|
|
|
QMap<QString, QString> m_translations;
|
|
|
|
|
bool filtered;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// QAbstractItemModel interface
|
|
|
|
|
public:
|
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role) override
|
|
|
|
@ -236,10 +267,21 @@ public:
|
|
|
|
|
rawEntity->setProperty(rawEntity->metaObject()->property(index.column() + 1).name(), value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == Qt::CheckStateRole)
|
|
|
|
|
{
|
|
|
|
|
if (m_selectedRows.contains(index.row()))
|
|
|
|
|
{
|
|
|
|
|
m_selectedRows.removeOne(index.row());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_selectedRows.append(index.row());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit editCompleted();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // ODBTABLEMODEL_H
|
|
|
|
|
|
|
|
|
|