|
@@ -1,17 +1,56 @@
|
|
|
-#ifndef TABLECOLUMNLITERALS_H
|
|
|
-#define TABLECOLUMNLITERALS_H
|
|
|
+#ifndef DECLARATIONS_H
|
|
|
+#define DECLARATIONS_H
|
|
|
|
|
|
-#include <QString>
|
|
|
-#include <QStringLiteral>
|
|
|
+#include <QtCore>
|
|
|
|
|
|
-// [F]: These constants deviate slightly from const naming convention to reflect their sql column name.
|
|
|
+/*!
|
|
|
+ * \brief An alias for QString
|
|
|
+ *
|
|
|
+ * Very long description *with* **markdown?**
|
|
|
+ * - - -
|
|
|
+ * # Header
|
|
|
+ */
|
|
|
+using ColName = QString;
|
|
|
+using ColData = QVariant;
|
|
|
+using TableName = QString;
|
|
|
+using RowId = int;
|
|
|
+
|
|
|
+using TableNames = QStringList;
|
|
|
+// [G]: May lead to some confusion. TableData suggest data for the entire table.
|
|
|
+// but in reallity it is data per column *of single row* (unless i misunderstand)
|
|
|
+// [F]: That's correct. We could maybe call it EntryData or RowData?
|
|
|
+using RowData = QMap<ColName, ColData>;
|
|
|
+using ColumnData = QPair<ColName, ColData>;
|
|
|
+using ColumnNames = QStringList;
|
|
|
+using TableColumns = QMap<TableName, ColumnNames>;
|
|
|
+
|
|
|
+// [G]: Needs some work. Inheriting from QPair may be helpful but
|
|
|
+// may also be overkill. Lets determine the specific uses of DataPosition
|
|
|
+// and provide our own interface i would say.
|
|
|
+// [F]: Good idea! Implementing something similar to first and second methods
|
|
|
+// of QPair would be useful to carry over, or some other way of quickly and
|
|
|
+// unambiguously accessing the elements.
|
|
|
+struct DataPosition : QPair<TableName, RowId> {
|
|
|
+ TableName tableName;
|
|
|
+ RowId rowId;
|
|
|
+ DataPosition()
|
|
|
+ : tableName(first), rowId(second)
|
|
|
+ {}
|
|
|
+ DataPosition(TableName table_name, RowId row_id)
|
|
|
+ : QPair<TableName, RowId>::QPair(table_name, row_id),
|
|
|
+ tableName(first), rowId(second)
|
|
|
+ {}
|
|
|
+ DataPosition(const DataPosition& other) = default;
|
|
|
+ DataPosition& operator=(const DataPosition& other) = default;
|
|
|
+};
|
|
|
+
|
|
|
+// [F]:
|
|
|
// In many places throughout the application, we have to programatically access or write data
|
|
|
// to or from the database using column names as identifiers, doing something like this:
|
|
|
//
|
|
|
// newData.insert("dept", ui->deptLocLineEdit->text());
|
|
|
// newData.value("multipilot") // do stuff
|
|
|
//
|
|
|
-//
|
|
|
// Declaring the literals here avoids memory allocation at runtime for construction of temporary qstrings
|
|
|
// like ("dept"). See https://doc.qt.io/qt-5/qstring.html#QStringLiteral
|
|
|
//
|
|
@@ -22,8 +61,12 @@ static const auto DB_TABLE_PILOTS = QStringLiteral("pilots");
|
|
|
static const auto DB_TABLE_TAILS = QStringLiteral("tails");
|
|
|
static const auto DB_TABLE_AIRCRAFT = QStringLiteral("aircraft");
|
|
|
static const auto DB_TABLE_AIRPORTS = QStringLiteral("airports");
|
|
|
-
|
|
|
-// Flights table
|
|
|
+// Default Positions
|
|
|
+static auto const DEFAULT_FLIGHT_POSITION = DataPosition(DB_TABLE_FLIGHTS, 0);
|
|
|
+static auto const DEFAULT_PILOT_POSITION = DataPosition(DB_TABLE_PILOTS, 0);
|
|
|
+static auto const DEFAULT_TAIL_POSITION = DataPosition(DB_TABLE_TAILS, 0);
|
|
|
+static auto const DEFAULT_AIRCRAFT_POSITION = DataPosition(DB_TABLE_AIRCRAFT, 0);
|
|
|
+// Flights table columns
|
|
|
static const auto DB_FLIGHTS_DOFT = QStringLiteral("doft");
|
|
|
static const auto DB_FLIGHTS_DEPT = QStringLiteral("dept");
|
|
|
static const auto DB_FLIGHTS_DEST = QStringLiteral("dest");
|
|
@@ -88,4 +131,5 @@ static const auto DB_ = QStringLiteral("");
|
|
|
static const auto DB_ = QStringLiteral("");
|
|
|
static const auto DB_ = QStringLiteral("");*/
|
|
|
|
|
|
-#endif // TABLECOLUMNLITERALS_H
|
|
|
+
|
|
|
+#endif // DECLARATIONS_H
|