some polishing

This commit is contained in:
Michael Zanetti 2020-08-27 14:19:28 +02:00
parent cfd6e0e1e9
commit b981333d3b
4 changed files with 39 additions and 37 deletions

View File

@ -240,6 +240,7 @@ void LogsModel::logsReply(const QVariantMap &data)
} }
if (newBlock.isEmpty()) { if (newBlock.isEmpty()) {
m_busyInternal = false;
m_busy = false; m_busy = false;
emit busyChanged(); emit busyChanged();
return; return;
@ -254,11 +255,13 @@ void LogsModel::logsReply(const QVariantMap &data)
endInsertRows(); endInsertRows();
emit countChanged(); emit countChanged();
m_busy = false; m_busyInternal = false;
emit busyChanged();
if (m_viewStartTime.isValid() && m_list.count() > 0 && m_list.last()->timestamp() > m_viewStartTime && m_canFetchMore) { if (m_viewStartTime.isValid() && m_list.count() > 0 && m_list.last()->timestamp() > m_viewStartTime && m_canFetchMore) {
fetchMore(); fetchMore();
} else {
m_busy = false;
emit busyChanged();
} }
} }
@ -270,7 +273,7 @@ void LogsModel::fetchMore(const QModelIndex &parent)
qWarning() << "Cannot update. Engine not set"; qWarning() << "Cannot update. Engine not set";
return; return;
} }
if (m_busy) { if (m_busyInternal) {
return; return;
} }
@ -279,8 +282,11 @@ void LogsModel::fetchMore(const QModelIndex &parent)
return; return;
} }
m_busy = true; m_busyInternal = true;
emit busyChanged(); if (!m_busy) {
m_busy = true;
emit busyChanged();
}
QVariantMap params; QVariantMap params;
@ -325,7 +331,6 @@ void LogsModel::classBegin()
void LogsModel::componentComplete() void LogsModel::componentComplete()
{ {
m_busy = false;
fetchMore(); fetchMore();
} }

View File

@ -124,10 +124,12 @@ protected:
QDateTime m_endTime; QDateTime m_endTime;
QDateTime m_viewStartTime; QDateTime m_viewStartTime;
bool m_busy = true; bool m_busy = false;
bool m_live = false; bool m_live = false;
int m_blockSize = 100; int m_blockSize = 100;
bool m_busyInternal = false;
bool m_canFetchMore = true; bool m_canFetchMore = true;
}; };

View File

@ -232,7 +232,7 @@ Page {
Behavior on opacity { NumberAnimation { duration: 200; easing.type: Easing.InOutQuad } } Behavior on opacity { NumberAnimation { duration: 200; easing.type: Easing.InOutQuad } }
Repeater { Repeater {
model: filteredContentModel model: d.configOverlay != null ? null : filteredContentModel
delegate: Loader { delegate: Loader {
width: swipeView.width width: swipeView.width
@ -280,7 +280,7 @@ Page {
Repeater { Repeater {
id: tabsRepeater id: tabsRepeater
model: filteredContentModel model: d.configOverlay != null ? null : filteredContentModel
delegate: MainPageTabButton { delegate: MainPageTabButton {
alignment: app.landscape ? Qt.Horizontal : Qt.Vertical alignment: app.landscape ? Qt.Horizontal : Qt.Vertical

View File

@ -63,23 +63,25 @@ MainViewBase {
Flickable { Flickable {
anchors.fill: parent anchors.fill: parent
topMargin: app.margins
contentHeight: energyGrid.childrenRect.height contentHeight: energyGrid.childrenRect.height
GridLayout { GridLayout {
id: energyGrid id: energyGrid
width: parent.width width: parent.width
visible: consumers.count > 0 visible: consumers.count > 0
columns: Math.floor(root.width / 300) columns: root.width > 600 ? 2 : 1
rowSpacing: 0 rowSpacing: 0
SmartMeterChart { SmartMeterChart {
Layout.fillWidth: true Layout.preferredWidth: energyGrid.width / energyGrid.columns
Layout.preferredHeight: width * .7 Layout.preferredHeight: width * .7
meters: consumers meters: consumers
title: qsTr("Total consumed energy") title: qsTr("Total consumed energy")
visible: consumers.count > 0 visible: consumers.count > 0
} }
ChartView { ChartView {
id: chartView id: chartView
Layout.fillWidth: true Layout.fillWidth: true
@ -88,23 +90,19 @@ MainViewBase {
legend.font.pixelSize: app.smallFont legend.font.pixelSize: app.smallFont
legend.visible: false legend.visible: false
backgroundColor: app.backgroundColor backgroundColor: app.backgroundColor
title: qsTr("Power usage history")
property var startTime: xAxis.min property var startTime: xAxis.min
property var endTime: xAxis.max property var endTime: xAxis.max
property int sampleRate: XYSeriesAdapter.SampleRateMinute property int sampleRate: XYSeriesAdapter.SampleRateMinute
property int busyModels: 0
BusyIndicator { BusyIndicator {
anchors.centerIn: parent anchors.centerIn: parent
visible: running visible: chartView.busyModels > 0
running: { running: visible
for (var i = 0; i < consumersRepeater.count; i++) {
if (consumersRepeater.itemAt(i).model.busy) {
return true;
}
}
return false;
}
} }
Repeater { Repeater {
@ -122,6 +120,13 @@ MainViewBase {
typeIds: [consumer.thing.thingClass.stateTypes.findByName("currentPower").id] typeIds: [consumer.thing.thingClass.stateTypes.findByName("currentPower").id]
viewStartTime: xAxis.min viewStartTime: xAxis.min
live: true live: true
onBusyChanged: {
if (busy) {
chartView.busyModels++
} else {
chartView.busyModels--
}
}
} }
property XYSeriesAdapter adapter: XYSeriesAdapter { property XYSeriesAdapter adapter: XYSeriesAdapter {
id: seriesAdapter id: seriesAdapter
@ -176,8 +181,6 @@ MainViewBase {
areaSeries.color = color; areaSeries.color = color;
areaSeries.borderColor = color; areaSeries.borderColor = color;
areaSeries.borderWidth = 0; areaSeries.borderWidth = 0;
seriesAdapter.xySeries = series;
} }
} }
} }
@ -190,17 +193,8 @@ MainViewBase {
onMinChanged: applyNiceNumbers(); onMinChanged: applyNiceNumbers();
onMaxChanged: applyNiceNumbers(); onMaxChanged: applyNiceNumbers();
labelsFont.pixelSize: app.smallFont labelsFont.pixelSize: app.smallFont
labelFormat: { labelFormat: "%d"
return "%d";
// switch (root.stateType.type.toLowerCase()) {
// case "bool":
// return "x";
// default:
// return "%d";
// }
}
labelsColor: app.foregroundColor labelsColor: app.foregroundColor
// tickCount: root.stateType.type.toLowerCase() === "bool" ? 2 : chartView.height / 40
color: Qt.rgba(app.foregroundColor.r, app.foregroundColor.g, app.foregroundColor.b, .2) color: Qt.rgba(app.foregroundColor.r, app.foregroundColor.g, app.foregroundColor.b, .2)
gridLineColor: color gridLineColor: color
} }
@ -273,7 +267,7 @@ MainViewBase {
min: { min: {
var date = new Date(); var date = new Date();
date.setTime(date.getTime() - (1000 * 60 * 60 * 24) + 2000); date.setTime(date.getTime() - (1000 * 60 * 60 * 6) + 2000);
return date; return date;
} }
max: { max: {
@ -304,7 +298,7 @@ MainViewBase {
} }
// figure out if we scrolled too far // figure out if we scrolled too far
var overshoot = xAxis.max.getTime() - now.getTime() var overshoot = xAxis.max.getTime() - now.getTime()
// print("overshoot is:", overshoot, "oldMax", xAxis.max, "newMax", now, "oldMin", xAxis.min, "newMin", new Date(xAxis.min.getTime() - overshoot)) // print("overshoot is:", overshoot, "oldMax", xAxis.max, "newMax", now, "oldMin", xAxis.min, "newMin", new Date(xAxis.min.getTime() - overshoot))
if (overshoot > 0) { if (overshoot > 0) {
var range = xAxis.max - xAxis.min var range = xAxis.max - xAxis.min
xAxis.max = now xAxis.max = now
@ -330,13 +324,13 @@ MainViewBase {
preventStealing = true preventStealing = true
} }
onClicked: { onClicked: {
// var pt = chartView.mapToValue(Qt.point(mouse.x + chartView.plotArea.x, mouse.y + chartView.plotArea.y), mainSeries) // var pt = chartView.mapToValue(Qt.point(mouse.x + chartView.plotArea.x, mouse.y + chartView.plotArea.y), mainSeries)
// mainSeries.markClosestPoint(pt) // mainSeries.markClosestPoint(pt)
} }
onWheel: { onWheel: {
scrollRightLimited(-wheel.pixelDelta.x) scrollRightLimited(-wheel.pixelDelta.x)
// zoomInLimited(wheel.pixelDelta.y) // zoomInLimited(wheel.pixelDelta.y)
} }
onPositionChanged: { onPositionChanged: {
@ -361,6 +355,7 @@ MainViewBase {
scrollMouseArea.scrollRightLimited(10) scrollMouseArea.scrollRightLimited(10)
} }
} }
} }
} }