This is more for me than the end user, because if there is an error with
a query, there is—almost aways—nothing a user can do, since it is
probably an error in the static SQL string or the database. However, it
is better to show an error, than to do nothing at all when there is a
failure.
According to Qt’s documentation[0], QFuture relies on exceptions for the
error handling. At first i assumed that i had to attach an onFailed
handler to QFuture in order to receive that exception and skip the then
handler.
However, i can not attach the onFailure inside Database::query, before
returning the QFuture, because the subsequent then is only executed when
there _is_ an error, never in the normal, non-exceptional, case. I
would have to add the onFailure after then.
Nonetheless, i found out that there is no need for onFailure: since i do
not call result(), i do not get the exception, and the actual work is
performed in the then handler when no exception is raised.
[0]: https://doc.qt.io/qt-6/qfuture.html
TimelineView is not a general control that can be used with any model,
thus i do not need the complexity of Qt’s QQmlDelegateModel incubation
task to initialize required properties. I _would_ have used it if it
were available in C++, but since it is not, what i mean is that i do not
need to _reimplement_ all of it for my case: i already know what
required properties there are.
These are a lot like TimelineDayRow and TimelineDayModel, and are
supposed to go in the timeline’s header too, but instead of showing the
day number, they show the month name.
I still need to know the with of each day, because the month must be as
wide as all shown days, that may not be all the days in that month, in
the first and last months, at least.
Usually i will show two or three months, so i thing is is fair to keep a
list of all the months and their days, rather than compute them each
time the name or the day count, two times per month, are requested.
I have my doubts whether this model should be QAbstractListModel-derived
or not. At first i thought i could not be, because i need to be able to
get a “view” (i.e., a [begin, end) pair of iterators) based on the
segment of TimelineView that becomes exposed due to scroll. However,
QAbstractItemModel::match returns a QModelIndexList, and that could also
be used for the same purpose, except that there is no QDateRange….
Until i have more needs for this model, the current coupling between
TimelineModel and TimelineView is OK, as i do not expect TimelineView to
be used for anything else.
I also renamed CalendarModel to TimelineListModel, since this is the
important part—the timeline—, and there is no “calendar” thing anywhere
in the application—at least, not what traditionally is understood as a
calendar, that is.
This is the equivalent control to Qt Quick Controls’ own DayOfWeekRow,
but for the number of each day in the visible range, instead of day of
the week.
Qt Quick Controls has this component written in C++, and also has a
separate, internal, model for the days in different formats, but i had
to implement the control in QML, because QtQuickControl is private.
However, as far as i understand, it is not much more than a container
for the delegate and the model that is used as a template.
This is supposed to be like a kind of horizontal ListView, however the
elements need to be placed according to its starting date, and must be
as long as the number of days of the stay. As far as i know, i can not
do that with a Qt-provided ListView because it has a strict one-to-one
mapping between QModelIndex’s row and visual element’s row (i.e., the
first item is always the first row, the second item the second row,
etc.), while i to have “holes” in the rows for item that are not
continous in time.
Unfortunately, Qt Quick does not provide a C++ API, meaning that i can
not derive from QQuickListView or, rather, QQuickItemView, without using
the private API. And that API is private for a reason; i do not want to
see myself redoing the control because they have changed who knows what.
Thus, had to base this control on QQuickItem.
I am also pretty sure i will not be able to use QAbstractItemModel for
this control, as, again, that model assumes that everything is
continuous: lists have rows next to each other, tables columns next to
each other, and trees are “just” nested tables. But i am not certain
yet.
Meanwhile, what i really need to do is to show a delegate for each
“filled in” day, and that’s is what this controls does for now. Since i
can not inherit from QQuickFlickable—not that it would be a great idea
here, since i need a list of these views anyway—, i have to know the
viewport’s position and width in order to have only the minimum number
of items visible. I do like QQmlDelgateModel (that i can not reuse
without private API), and reuse the delegates when possible.
This is to tell screen readers that have to read the text in the
notification, or the notification pops up and orca, at least, does not
know that it needs to read it.
I also had to change the role of SelectableLabel’s TextArea to
StaticText or orca would only read the first line. Not sure if that is
an error, because TextArea does indeed behave like a StaticText (i.e., a
label) in this case, but TextArea has Accessible.multiLine set to true.
This is to give a default name to form controls by default, like <label>
does to <input> and <textarea> in HTML.
Had to add a “plain” version of the label, with neither the <u> tag used
in rich text or the ‘&’ in the “regular” label, otherwise orca would
spell out these symbols.
I am using .pg_service.conf to define all connection parameters, and
.pgpass for the password, thus i never have to input anything to the
login form, and want to skip it.
However, just in case someday i need to set the connection up
differently, i only try to log in automatically on startup, and can go
back to the login page by logging out, as usual.
To query the database, i have to run the query inside the same thread
where the database was created, which means that Database should be a
singleton not only within QML, but also in C++, and has to be the _same_
singleton in both worlds.
Although i expose an object that i have created, i followed the same
section titled “Exposing an existing object as a singleton” from Qt’s
documentation[0]. The only difference is that i do not have to declare
the element as a foreign type, because it is a bona fide QObject.
[0]: https://doc.qt.io/qt-6/qml-singleton.html#exposing-an-existing-
object-as-a-singleton
I only want to store these options if the connection to the database is
established, to avoid saving incorrect values by error. I, then, did not
use property alias, as the documentation reccomends, and instead have a
function to save the parameters when the application sees the database
open.
I have to use the function because a Connections inside LoginPage gets
called _after_ the Connections in Main, meaning that i would get deleted
before it has the chance to save the settings.
Now i can’t assume connect options will include search_path, as it is
unreasonable to request people to know the internal schemas of the
application.
For host, database name, and options i can leave them blank to use the
default value, but for the port i can’t with a SpinBox, since it _must_
have a value.
Qt’s driver uses -1 to mean “default port”, but i can not use the same
approach with the user interface, because there is no port -1, and makes
no sense to allow that value, specially since i then i have to allow 0
as well, which is a reserved port.
I also can not leave the SpinBox with PostgreSQL’s default port, 5432,
because that is slightly different than telling libpq to use the
“default”: if someone uses a ‘service=’ option, it would use the port in
the SpinBox rather than the one in ‘pg_service.conf’, if any.
My solution is to use a checkbox to tell the application “i wan to use a
port number”, and (will) only pass the port number if it is checked. On
the other hand, now i do not have a keyboard shortcut to focus on the
port number field.
I want to allow people to set all options of QSqlDatabase, that way i do
not force the ‘service=camper’ thing, and everyone can use whatever
parameters they see fit.
I plan to store these other options as Settings, because usualy this
should only be done once at setup, and then we only need to input the
username and login to enter. For that same reason, i do not want to
show them all the time; only if the user wants to change anything.
As far as i know, neither QtWidgets nor Qt Quick Controls have anything
that works as Gtk’s Expander, so i had to create that component. HTML
calls it <details>, Apple “disclosure control”[0], and both Microsoft
and Gtk “expander”[1, 2]. I’ve choosen Gtk name, but macOS looks.
[0]: https://developer.apple.com/design/human-interface-guidelines/
disclosure-controls
[1]: https://learn.microsoft.com/en-us/windows/apps/design/controls/
expander
[2]: https://docs.gtk.org/gtk4/class.Expander.html
This is to accept Alt+(whatever has & in front in the label) for labels,
buttons, actions, and whatever requires a nmenonic.
I created an attached property because it is kind of similar to QML’s
Keys property.
Since i only plan to use a single connection, i can use QtSql’s default
connection name.
According to the documentation, i have to make sure that no query or
database object is open when i remove the database. I now use C++
scopes for that, but i need to have a QString declared outside of it to
get the default connection’s name.
I want to perform all SQL queries in a thread, to avoid freezing the UI,
that sometimes might happen when there is a lot of data to fetch; should
not happen very often, though.
Neither libpq nor Qt SQL allow queries on the same connection from
differents threads, and, in Qt SQL, all queries must be performed from
the same thread where the connection was established. In Qt5 i had to
either create a connection per thread, or use a QThread-derived object
to hold the connection and use signals and slots to pass query and
response data between the UI and database threads; it was usable but not
pretty.
With Qt6 and Concurrent’s QThreadPool now i can use QFutures instead,
that are not as cumbersome as with Qt5, because i no longer need
QFutureWatcher. I still have the problem that all queries must be done
from within the same thread, and QThreadPool uses an arbitrary thread.
The solution is to create a “pool” with a single, non-expirable thread,
and call all Concurrent::run onto that pool.
I have to test it properly, and first need to open the database to test
whether that, at least, works. I added a simple “login page” for that,
and to make a first attempt to error messages; i use a control that is
like Kirigami’s InlineMessage for now, but i am not sure.
I also do not know how i will configure database’s connection details. I
usually make use of pg_service.conf, because then the application only
need to know its service name, but i am not sure whether other people
would find it as comfortable as i do.
We forgot that different accommodation types are not always operating on
the whole season calendar, thus we need a specific date for each type.
Someday i will add the field in the administration panel, but for now i
will have to add them by hand, as people are starting to book plots on
dates that are not operating.
I’ve removed the total amount because it is very difficult to get it
with pagination, and customer never saw it (it was from Numerus), thus
they won’t miss it—i hope.
To hold the common logic of detecting pagination, forming the key, and
splitting its values later on.
I can take advantage that a form with action="get" already adds its
fields to the query string to have a common template for pagination. The
only problem is that i have different column spans for different tables,
therefore had to add a colspan to the struct.
It is just the index of bookings in the created state, but we thought it
would make easier to understand the difference between a booking from
a customer not yet confirmed, from a booking confirmed or created by the
staff.
The idea is that we will marshal the payment, send it to the campsite’s
instance by email, and then unmarshal it as a booking, that way we can
have a one way replication from the internal to the public instance with
a way back to send the payments.
For testing purposes, i just create the booking in the same instance.
Had to change the booking relation’s permissions to allow insert from
a guest, much like for payments, because the notification from Redsys
comes as a guest connection. I need this even with all the
marshal/unmarshal shenanigans because not everyone will have an internal
instance, thus need to allow bookings from guest connections.
Most will be families living at the same address. And, if they are not,
it is far easier to replace the incorrect address with the actual,
rather than write the same address to all family members under the same
household.