mirror of
https://github.com/tnodir/fort
synced 2024-11-15 06:32:56 +00:00
UI: ZonesWindow: Checkable zones.
This commit is contained in:
parent
8873904492
commit
318d6759bd
@ -199,6 +199,12 @@ const char * const sqlUpdateZoneName =
|
||||
" WHERE zone_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const sqlUpdateZoneEnabled =
|
||||
"UPDATE zone"
|
||||
" SET enabled = ?2"
|
||||
" WHERE zone_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const sqlUpdateZoneResult =
|
||||
"UPDATE zone"
|
||||
" SET checksum = ?2, last_run = ?3, last_success = ?4"
|
||||
@ -701,6 +707,23 @@ bool ConfManager::updateZoneName(qint64 zoneId, const QString &zoneName)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateZoneEnabled(qint64 zoneId, bool enabled)
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
const auto vars = QVariantList()
|
||||
<< zoneId
|
||||
<< enabled
|
||||
;
|
||||
|
||||
m_sqliteDb->executeEx(sqlUpdateZoneEnabled, vars, 0, &ok);
|
||||
if (!ok) {
|
||||
showErrorMessage(m_sqliteDb->errorMessage());
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool ConfManager::updateZoneResult(qint64 zoneId, const QString &checksum,
|
||||
const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess)
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
const QString &sourceCode, const QString &url,
|
||||
const QString &formData, bool enabled, bool customUrl);
|
||||
bool updateZoneName(qint64 zoneId, const QString &zoneName);
|
||||
bool updateZoneEnabled(qint64 zoneId, bool enabled);
|
||||
bool updateZoneResult(qint64 zoneId, const QString &checksum,
|
||||
const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess);
|
||||
|
@ -280,8 +280,8 @@ void ZonesWindow::setupTableZonesHeader()
|
||||
header->setSectionResizeMode(2, QHeaderView::Stretch);
|
||||
header->setSectionResizeMode(3, QHeaderView::Stretch);
|
||||
|
||||
header->resizeSection(0, 500);
|
||||
header->resizeSection(1, 140);
|
||||
header->resizeSection(0, 350);
|
||||
header->resizeSection(1, 290);
|
||||
}
|
||||
|
||||
void ZonesWindow::setupTableZonesChanged()
|
||||
|
@ -84,18 +84,14 @@ int AppListModel::columnCount(const QModelIndex &parent) const
|
||||
QVariant AppListModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal) {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: {
|
||||
switch (section) {
|
||||
case 0: return tr("Program");
|
||||
case 1: return tr("Group");
|
||||
case 2: return tr("State");
|
||||
case 3: return tr("End Time");
|
||||
case 4: return tr("Creation Time");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (orientation == Qt::Horizontal
|
||||
&& role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case 0: return tr("Program");
|
||||
case 1: return tr("Group");
|
||||
case 2: return tr("State");
|
||||
case 3: return tr("End Time");
|
||||
case 4: return tr("Creation Time");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -36,17 +36,13 @@ int ZoneListModel::columnCount(const QModelIndex &parent) const
|
||||
|
||||
QVariant ZoneListModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal) {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole: {
|
||||
switch (section) {
|
||||
case 0: return tr("Zone");
|
||||
case 1: return tr("Source");
|
||||
case 2: return tr("Last Run");
|
||||
case 3: return tr("Last Success");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (orientation == Qt::Horizontal
|
||||
&& role == Qt::DisplayRole) {
|
||||
switch (section) {
|
||||
case 0: return tr("Zone");
|
||||
case 1: return tr("Source");
|
||||
case 2: return tr("Last Run");
|
||||
case 3: return tr("Last Success");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
@ -79,11 +75,45 @@ QVariant ZoneListModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::CheckStateRole:
|
||||
if (index.column() == 0) {
|
||||
const auto zoneRow = zoneRowAt(index.row());
|
||||
return zoneRow.enabled;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool ZoneListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
Q_UNUSED(value)
|
||||
|
||||
if (!index.isValid())
|
||||
return false;
|
||||
|
||||
switch (role) {
|
||||
case Qt::CheckStateRole:
|
||||
const auto zoneRow = zoneRowAt(index.row());
|
||||
return updateZoneEnabled(zoneRow.zoneId, !zoneRow.enabled);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::ItemFlags ZoneListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::NoItemFlags;
|
||||
|
||||
const int column = index.column();
|
||||
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemNeverHasChildren
|
||||
| (column == 0 ? Qt::ItemIsUserCheckable : Qt::NoItemFlags);
|
||||
}
|
||||
|
||||
const ZoneRow &ZoneListModel::zoneRowAt(int row) const
|
||||
{
|
||||
updateRowCache(row);
|
||||
@ -128,6 +158,16 @@ bool ZoneListModel::updateZoneName(qint64 zoneId, const QString &zoneName)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZoneListModel::updateZoneEnabled(qint64 zoneId, bool enabled)
|
||||
{
|
||||
if (confManager()->updateZoneEnabled(zoneId, enabled)) {
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZoneListModel::updateZoneResult(qint64 zoneId, const QString &checksum,
|
||||
const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess)
|
||||
|
@ -45,6 +45,9 @@ public:
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
const ZoneRow &zoneRowAt(int row) const;
|
||||
|
||||
@ -56,6 +59,7 @@ public:
|
||||
const QString &formData, bool enabled, bool customUrl,
|
||||
bool updateDriver = true);
|
||||
bool updateZoneName(qint64 zoneId, const QString &zoneName);
|
||||
bool updateZoneEnabled(qint64 zoneId, bool enabled);
|
||||
bool updateZoneResult(qint64 zoneId, const QString &checksum,
|
||||
const QDateTime &lastRun,
|
||||
const QDateTime &lastSuccess);
|
||||
|
Loading…
Reference in New Issue
Block a user