Emit correct roles when colors changed
This commit is contained in:
parent
edb6f10e62
commit
030cb35dbd
|
@ -38,6 +38,12 @@ QHash<int, QByteArray> SyncthingDeviceModel::roleNames() const
|
|||
return roles;
|
||||
}
|
||||
|
||||
const QVector<int> &SyncthingDeviceModel::colorRoles() const
|
||||
{
|
||||
static const QVector<int> colorRoles({ Qt::ForegroundRole, DeviceStatusColor });
|
||||
return colorRoles;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the device info for the spcified \a index. The returned object is not persistent.
|
||||
*/
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
|
||||
public Q_SLOTS:
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
const QVector<int> &colorRoles() const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
|
|
|
@ -44,6 +44,12 @@ QHash<int, QByteArray> SyncthingDirectoryModel::roleNames() const
|
|||
return roles;
|
||||
}
|
||||
|
||||
const QVector<int> &SyncthingDirectoryModel::colorRoles() const
|
||||
{
|
||||
static const QVector<int> colorRoles({ Qt::ForegroundRole, DirectoryStatusColor });
|
||||
return colorRoles;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the directory info for the spcified \a index. The returned object is not persistent.
|
||||
*/
|
||||
|
|
|
@ -28,6 +28,7 @@ public:
|
|||
|
||||
public Q_SLOTS:
|
||||
QHash<int, QByteArray> roleNames() const;
|
||||
const QVector<int> &colorRoles() const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
|
|
|
@ -9,11 +9,20 @@ SyncthingModel::SyncthingModel(SyncthingConnection &connection, QObject *parent)
|
|||
{
|
||||
}
|
||||
|
||||
const QVector<int> &SyncthingModel::colorRoles() const
|
||||
{
|
||||
static const QVector<int> colorRoles;
|
||||
return colorRoles;
|
||||
}
|
||||
|
||||
void SyncthingModel::setBrightColors(bool brightColors)
|
||||
{
|
||||
if (m_brightColors != brightColors) {
|
||||
m_brightColors = brightColors;
|
||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1), QVector<int>() << Qt::ForegroundRole);
|
||||
const QVector<int> &affectedRoles = colorRoles();
|
||||
if (!affectedRoles.isEmpty()) {
|
||||
emit dataChanged(index(0, 0), index(rowCount() - 1, columnCount() - 1), affectedRoles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ public:
|
|||
void setBrightColors(bool brightColors);
|
||||
|
||||
protected:
|
||||
virtual const QVector<int> &colorRoles() const;
|
||||
|
||||
Data::SyncthingConnection &m_connection;
|
||||
bool m_brightColors;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue