Compare commits

..

No commits in common. "8c222c6f6b4c650ac38cb8fcfb5073d85c87dcee" and "ab1ebd61b667eecfa8c3537353113527c9609095" have entirely different histories.

5 changed files with 31 additions and 97 deletions

View File

@ -7,12 +7,11 @@ Label {
required property Item dragParent required property Item dragParent
required property string holder required property string holder
required property int nights
required property int reservationId
required property string reservationStatus required property string reservationStatus
Drag.active: dragHandler.active Drag.active: dragHandler.active
Drag.hotSpot.y: height / 2 Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
elide: Text.ElideRight elide: Text.ElideRight
padding: 2 padding: 2
text: holder text: holder

View File

@ -99,16 +99,29 @@ Control {
id: verticalScroll id: verticalScroll
} }
delegate: TimelineView { delegate: DropArea {
property real contentWidth: ListView.view.contentWidth
required property string name
required property TimelineModel timeline required property TimelineModel timeline
property real viewportWidth: ListView.view.width
property real viewportX: ListView.view.contentX
height: control.rowHeight
width: contentWidth
onPositionChanged: function (drag) {
drag.source.y = y;
drag.source.x = (Math.floor(drag.x / control.dayWidth) + .5) * control.dayWidth;
}
TimelineView {
dayWidth: control.dayWidth dayWidth: control.dayWidth
fromDate: control.fromDate fromDate: control.fromDate
height: control.rowHeight height: parent.height
model: timeline model: parent.timeline
toDate: control.toDate toDate: control.toDate
viewportWidth: ListView.view.width viewportWidth: parent.viewportWidth
viewportX: ListView.view.contentX viewportX: parent.viewportX
delegate: Reservation { delegate: Reservation {
dragParent: timelineList.contentItem dragParent: timelineList.contentItem
@ -121,6 +134,7 @@ Control {
palette: control.palette palette: control.palette
} }
} }
}
header: Rectangle { header: Rectangle {
border.color: Fusion.outline(control.palette) border.color: Fusion.outline(control.palette)
color: control.palette.base color: control.palette.base
@ -187,51 +201,5 @@ Control {
} }
} }
} }
DropArea {
property int prevDay
property int prevLodging
function addDays(date, days) {
var newDate = new Date(date);
newDate.setDate(date.getDate() + days);
return newDate;
}
function findDayAndLodging(drag: DragEvent): list<int> {
const pos = timelineList.contentItem.mapFromItem(this, drag.x, drag.y);
const day = Math.floor(pos.x / control.dayWidth);
const lodging = Math.floor(pos.y / control.rowHeight);
return [day, lodging];
}
function isSpotAvailable(day: int, lodging: int, reservation: Reservation): bool {
const view = timelineList.itemAtIndex(lodging);
if (!view) {
return false;
}
return view.timeline.areDatesAvailable(addDays(control.fromDate, day), addDays(control.fromDate, day + reservation.nights), reservation.reservationId);
}
anchors.fill: timelineList
anchors.leftMargin: -30 * control.dayWidth
onEntered: function (drag) {
[prevDay, prevLodging] = findDayAndLodging(drag);
}
onPositionChanged: function (drag) {
let [day, lodging] = findDayAndLodging(drag);
if ((day != prevDay || lodging != prevLodging) && isSpotAvailable(day, lodging, drag.source)) {
prevDay = day;
prevLodging = lodging;
} else {
day = prevDay;
lodging = prevLodging;
}
drag.source.y = lodging * control.rowHeight;
drag.source.x = (day + .5) * control.dayWidth;
}
}
} }
} }

View File

@ -16,31 +16,6 @@ void TimelineModel::update(const QList<Item *> &items)
m_items.assign(items.begin(), items.end()); m_items.assign(items.begin(), items.end());
} }
bool TimelineModel::areDatesAvailable(QDate arrival, QDate departure, int excludedId) const
{
auto [begin, end] = indexesOf(arrival, departure);
if (begin == end) {
return true;
}
const Item *first = m_items.at(begin);
if (first->id == excludedId) {
begin++;
if (begin == end) {
return true;
}
first = m_items.at(begin);
}
const Item *last = m_items.at(end - 1);
if (last->id == excludedId) {
--end;
if (begin == end) {
return true;
}
last = m_items.at(end - 1);
}
return arrival >= last->departure() || departure <= first->arrival;
}
std::pair<qsizetype, qsizetype> TimelineModel::indexesOf(QDate from, QDate to) const std::pair<qsizetype, qsizetype> TimelineModel::indexesOf(QDate from, QDate to) const
{ {
qsizetype begin = searchIndex(from); qsizetype begin = searchIndex(from);
@ -50,16 +25,13 @@ std::pair<qsizetype, qsizetype> TimelineModel::indexesOf(QDate from, QDate to) c
while (begin > 0) { while (begin > 0) {
--begin; --begin;
const Item *item = m_items.at(begin);
if (m_items.at(begin)->departure() < from) { if (m_items.at(begin)->departure() < from) {
++begin; ++begin;
break; break;
} }
} }
if (begin == 0 && m_items.at(begin)->arrival >= to) {
return std::make_pair(begin, begin);
}
for (qsizetype end = begin + 1; end < m_items.count(); end++) { for (qsizetype end = begin + 1; end < m_items.count(); end++) {
if (m_items.at(end)->arrival >= to) { if (m_items.at(end)->arrival >= to) {
return std::make_pair(begin, end); return std::make_pair(begin, end);

View File

@ -31,7 +31,6 @@ public:
void update(const QList<Item *> &items); void update(const QList<Item *> &items);
Q_INVOKABLE bool areDatesAvailable(QDate arrival, QDate departure, int excludeId) const;
std::pair<qsizetype, qsizetype> indexesOf(QDate from, QDate to) const; std::pair<qsizetype, qsizetype> indexesOf(QDate from, QDate to) const;
const Item *at(qsizetype index) const; const Item *at(qsizetype index) const;

View File

@ -174,8 +174,6 @@ TimelineView::Item *TimelineView::createItem(qint64 day, const TimelineModel::It
if (m_reusableItems.isEmpty()) { if (m_reusableItems.isEmpty()) {
QVariantMap initialProperties{ QVariantMap initialProperties{
{"holder", modelItem.holder}, {"holder", modelItem.holder},
{"nights", modelItem.nights},
{"reservationId", modelItem.id},
{"reservationStatus", modelItem.status}, {"reservationStatus", modelItem.status},
}; };
item = qobject_cast<QQuickItem *>( item = qobject_cast<QQuickItem *>(
@ -188,8 +186,6 @@ TimelineView::Item *TimelineView::createItem(qint64 day, const TimelineModel::It
} else { } else {
item = m_reusableItems.takeLast(); item = m_reusableItems.takeLast();
item->setProperty("holder", modelItem.holder); item->setProperty("holder", modelItem.holder);
item->setProperty("nights", modelItem.nights);
item->setProperty("reservationId", modelItem.id);
item->setProperty("reservationStatus", modelItem.status); item->setProperty("reservationStatus", modelItem.status);
} }
auto *viewItem = new TimelineView::Item(day, modelItem.nights, *item, *this); auto *viewItem = new TimelineView::Item(day, modelItem.nights, *item, *this);