check date called from firebase against calendar?
-
Hey guys,
I am working with QML saving Calendar selected dates into a firebase database. when i open the calendar page i am then reading the saved dates back.
I need to check the dates from firebase to the calendar and any date saved will display a marker?
how could i set this up? as i'm well and truly stuck XD
Thanks!
-
@Ldweller
Hi
Subclass QCalendarWidget and override
http://doc.qt.io/qt-5/qcalendarwidget.html#paintCell
so you can draw the marker.
Open DB and store the "marked" date in a lookup list
so when paintCell is called, you check the date paramter against
the data and draw marker if needed. -
@mrjj Thanks for getting back to be so fast! and thanks for the response!!
I am using the QtQuick Calendar would this method still be able to be applied?
When you say lookup list, by what do you mean(sorry if it's an obvious question?)
my dates are stored like so, would this be the appropriate way to get it working?
---dates
------1
---------date: "2018-09-03"
------2
---------date: "2018-09-04"
------3
---------date: "2018-09-05"Thanks again!
-
@Ldweller
Hi
oh, its QML. nope that is different.
I think you can make your own
http://doc.qt.io/qt-5/qml-qtquick-controls-styles-calendarstyle.html
if the default is not looking like you want. else default is fine.
And also forget about the looup list. :) not needed.
The QML calendar uses a model based SqlQueryModel so all you really need
is change the database type and the query in
void SqlEventModel::createConnection()
in sample ( you linked) it just creates a table and put data in.
you would just read the ones you have. ( SQL select statement) -
@mrjj
again I can't thank you enough for the help!I have amended my original post stating I am working in QML and added the QML tag also.
forgive me, I am a novice but adamant to complete this project and learning unfathomable amounts along the way assisted by the likes of you!
There is already a QML project example with saved dates marked using SQLite, yet I chose firebase for the cloud hosted backend, noSQL and no additional setup there for me! When you have said change the database type do you mean to stop using firebase and move to SQL? or is there a way I can translate my firebase callbacks into and SQL event model?
Thanks a million again!!!
-
@Ldweller
Ok super.
Next step would be to alter
QList<QObject*> SqlEventModel::eventsForDate(const QDate &date)
to use your table names / col names to get any events that need to be drawn.I assume you can use QSqlQuery with firebase or is that the actual issue ?
its non sql and u use completely another method of getting data ?
IF yes, i think we need to use other model then. -
firebase is noSQL with data stored as JSON so i have no tables to work with;
a simple read value for me would be;firebaseDB.getUserValue("users/details/firstname")
I can query firebase also with filter by key/value/child options.
Would you suggest working with Sql then?
Thanks
-
@mrjj
I have moved forward from calling my saved dates to receive the following:Read Value: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object] for key: dates
(one for each date saved)
when addingif(success) { console.log(JSON.stringify(value)) }
I can also read the saved dates in the format of:
[{"date":"2018-10-01T21:17:00.926"},{"date":"2018-10-02T12:00:00.000"},{"date":"2018-10-03T12:00:00.000"},{"date":"2018-10-06T12:00:00.000"},{"date":"2018-10-07T12:00:00.000"},{"date":"2018-10-08T12:00:00.000"}]
now how would I determine these dates are saved in my calendar to add the marker?
I have tried adding a property bool to the marker so the read value equals isMarked = true yet this either marks every date on the calendar or none at all depending on how I am working this?!?
How would I convert the JSON string to individual date reads?