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 string holder
required property int nights
required property int reservationId
required property string reservationStatus
Drag.active: dragHandler.active
Drag.hotSpot.y: height / 2
Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
elide: Text.ElideRight
padding: 2
text: holder

View File

@ -99,26 +99,40 @@ Control {
id: verticalScroll
}
delegate: TimelineView {
delegate: DropArea {
property real contentWidth: ListView.view.contentWidth
required property string name
required property TimelineModel timeline
property real viewportWidth: ListView.view.width
property real viewportX: ListView.view.contentX
dayWidth: control.dayWidth
fromDate: control.fromDate
height: control.rowHeight
model: timeline
toDate: control.toDate
viewportWidth: ListView.view.width
viewportX: ListView.view.contentX
width: contentWidth
delegate: Reservation {
dragParent: timelineList.contentItem
onPositionChanged: function (drag) {
drag.source.y = y;
drag.source.x = (Math.floor(drag.x / control.dayWidth) + .5) * control.dayWidth;
}
Separator {
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
palette: control.palette
TimelineView {
dayWidth: control.dayWidth
fromDate: control.fromDate
height: parent.height
model: parent.timeline
toDate: control.toDate
viewportWidth: parent.viewportWidth
viewportX: parent.viewportX
delegate: Reservation {
dragParent: timelineList.contentItem
}
Separator {
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
palette: control.palette
}
}
}
header: Rectangle {
@ -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());
}
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
{
qsizetype begin = searchIndex(from);
@ -50,16 +25,13 @@ std::pair<qsizetype, qsizetype> TimelineModel::indexesOf(QDate from, QDate to) c
while (begin > 0) {
--begin;
const Item *item = m_items.at(begin);
if (m_items.at(begin)->departure() < from) {
++begin;
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++) {
if (m_items.at(end)->arrival >= to) {
return std::make_pair(begin, end);

View File

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