Commit fb70098d authored by Julien Boulay's avatar Julien Boulay Committed by André Hoarau
Browse files

fix : locationTask are hidden by Planting tasks in the location view. Add new...

fix : locationTask are hidden by Planting tasks in the location view. Add new rows for location taskTimeline.
parent f1aea227
......@@ -443,8 +443,8 @@ QMap<int, QVariantList> Location::allNonOverlappingPlantingList(int season, int
QMap<int, QVariantList> map;
int locationId = query->value("location_id").toInt();
QVector<QVariantList> rows;
rows.push_back({ query->value("planting_id").toInt() });
QVector<QVariantList> currentTimelineRows;
currentTimelineRows.push_back({ query->value("planting_id").toInt() });
// rowDate[i] is pair of the planting and end harvest dates of the last planting we added
// to row i.
......@@ -452,32 +452,31 @@ QMap<int, QVariantList> Location::allNonOverlappingPlantingList(int season, int
rowDate.push_back({ QrpDate::dateFromIsoString(query->value("planting_date").toString()),
QrpDate::dateFromIsoString(query->value("end_harvest_date").toString()) });
int lid;
int nextLocationId;
int plantingId;
int i;
while (query->next()) {
lid = query->value("location_id").toInt();
nextLocationId = query->value("location_id").toInt();
plantingId = query->value("planting_id").toInt();
auto plantingDate = QrpDate::dateFromIsoString(query->value("planting_date").toString());
auto endHarvestDate = QrpDate::dateFromIsoString(query->value("end_harvest_date").toString());
if (lid != locationId) {
if (nextLocationId != locationId) {
// We've found a new location, so we add the list we've just built to the QMap
// and clear the temporary lists.
// Since QML cannot use a QList of QList<int>, we convert the
// list to a QVariantList. This may introduce a performance problem,
// but it is a working solution.
QVariantList variantList;
for (const auto &lst : rows) {
if (!lst.isEmpty())
variantList.push_back(lst);
QVariantList timelineRows;
for (const auto &timelineRow : currentTimelineRows) {
if (!timelineRow.isEmpty())
timelineRows.push_back(timelineRow);
}
map[locationId] = variantList;
rows.clear();
map[locationId] = timelineRows;
currentTimelineRows.clear();
rowDate.clear();
locationId = lid;
rows.push_back({ plantingId });
// rows.push_back({ m_planting->drawInfoMap(query->record(), season, year, false, true) });
locationId = nextLocationId;
currentTimelineRows.push_back({ plantingId });
rowDate.push_back({ plantingDate, endHarvestDate });
continue;
}
......@@ -485,8 +484,7 @@ QMap<int, QVariantList> Location::allNonOverlappingPlantingList(int season, int
i = 0;
for (; i < rowDate.count(); ++i) {
if (!overlap(rowDate[i].first, rowDate[i].second, plantingDate, endHarvestDate)) {
rows[i].push_back(plantingId);
// rows[i].push_back(m_planting->drawInfoMap(query->record(), season, year, false, true));
currentTimelineRows[i].push_back(plantingId);
rowDate[i] = { plantingDate, endHarvestDate };
break;
}
......@@ -496,14 +494,13 @@ QMap<int, QVariantList> Location::allNonOverlappingPlantingList(int season, int
// The current planting overlaps every plantings we've already assigned,
// so we create a new row for it.
rowDate.push_back({ plantingDate, endHarvestDate });
rows.push_back({ plantingId });
// rows.push_back({ m_planting->drawInfoMap(query->record(), season, year, false, true) });
currentTimelineRows.push_back({ plantingId });
}
}
// Add last location.
QVariantList variantList;
for (const auto &lst : rows) {
for (const auto &lst : currentTimelineRows) {
if (!lst.isEmpty())
variantList.push_back(lst);
}
......@@ -766,10 +763,11 @@ QMap<int, QVariantList> Location::allRotationConflictingPlantings(int season, in
CropRotationInfoList infoList;
const auto push = [&infoList, &query]() {
infoList.push_back({ query->value("planting_id").toInt(), query->value("crop").toString(),
query->value("family_id").toInt(), query->value("family_interval").toInt(),
QrpDate::dateFromIsoString(query->value("planting_date").toString()),
QrpDate::dateFromIsoString(query->value("end_harvest_date").toString()) });
infoList.push_back(
{ query->value("planting_id").toInt(), query->value("crop").toString(),
query->value("family_id").toInt(), query->value("family_interval").toInt(),
QrpDate::dateFromIsoString(query->value("planting_date").toString()),
QrpDate::dateFromIsoString(query->value("end_harvest_date").toString()) });
};
push();
......
......@@ -389,12 +389,13 @@ Item {
property var plantingRowList: model.nonOverlappingPlantingList
property var taskRowList: model.taskList
property int rows: plantingRowList.length
property int taskRows: taskRowList.length
property bool hasLocationTasks: taskRowList.length > plantingRowList.length
property bool isSelected: root.isSelected(currentRow)
clip: true
width: ListView.view.width // fill available width
height: Math.max(1,rows) * Units.rowHeight + 1 // always show at least one row
height: root.showTimeline ? Math.max(1,rows,taskRows) * Units.rowHeight + 1 : Units.rowHeight + 1 // always show at least one row
color: Qt.darker(model.hasChildren ? colorList[model.depth] : "white",
(isSelected) ? 1.1 : 1)
......@@ -608,20 +609,22 @@ Item {
Layout.fillWidth: true
MonthGrid {
visible: !locationDelegate.plantingRowList.length
id: monthGrid
height: parent.height
width: parent.width
}
TaskTimeline {
id: locationTaskTimeline
visible: locationDelegate.hasLocationTasks
visible: locationDelegate.hasLocationTasks && root.showTimeline
model: visible ? locationDelegate.taskRowList[taskRowList.length - 1] : []
seasonBegin: root.seasonBegin
season: root.season
year: root.year
height: locationDelegate.height
height: Units.rowHeight
y: locationDelegate.plantingRowList.length * Units.rowHeight
width: parent.width
}
Column {
......@@ -635,6 +638,8 @@ Item {
visible: root.showTimeline
year: root.year
season: root.season
showMonthGrid: false
showTodayLine: false
showGreenhouseSow: false
showNames: true
showTasks: locationSettings.showTasks
......
......@@ -38,7 +38,7 @@ Item {
width: taskMap["width"]
radius: 3
visible: duration > 0 && width > 0
height: parent.height - Units.rowHeight * 0.3
height: parent.height * 0.7
anchors.verticalCenter: parent.verticalCenter
color: taskColor
opacity: 0.8
......
......@@ -13,7 +13,6 @@ Item {
id: repeater
TaskTimegraph {
taskId: modelData
height: control.height
seasonBegin: control.seasonBegin
season: control.season
year: control.year
......
......@@ -34,9 +34,11 @@ Item {
property var plantingIdList
// property var plantingDrawMapList
property var taskIdList
property bool showMonthGrid: true
property bool showGreenhouseSow: true
property bool showOnlyActiveColor: false
property bool showFamilyColor: false
property bool showTodayLine: true
property int locationId: -1
property real locationLength: -1
property bool showNames: false
......@@ -61,13 +63,14 @@ Item {
id: gridRow
anchors.verticalCenter: parent.verticalCenter
height: parent.height
visible: showMonthGrid
}
Rectangle {
id: todayLine
x: Helpers.position(seasonBegin, todayDate)
z: 3
visible: x != 0 && x != graphWidth
visible: x != 0 && x != graphWidth && showTodayLine
width: 1
anchors.topMargin: -1
anchors.bottomMargin: -1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment