Browse Source

Added REPR macro for qDebugability convinience

George 4 years ago
parent
commit
fb1a7748d9
3 changed files with 34 additions and 12 deletions
  1. 3 2
      main.cpp
  2. 4 10
      src/database/declarations.h
  3. 27 0
      src/testing/adebug.h

+ 3 - 2
main.cpp

@@ -27,6 +27,7 @@
 #include <QSettings>
 #include <QFileInfo>
 #include <QStandardPaths>
+#include <QDebug>
 
 #define APPNAME "openPilotLog"
 #define ORGNAME APPNAME
@@ -42,7 +43,7 @@ int main(int argc, char *argv[])
     AStandardPaths::setup();
     AStandardPaths::scan_paths();
     if(!AStandardPaths::validate_paths()){
-        DEB("Standard paths not valid.");
+        DEB "Standard paths not valid.";
         return 1;
     }
 
@@ -58,7 +59,7 @@ int main(int argc, char *argv[])
     //Theming
     int selectedtheme = ASettings::getSettings().value("main/theme").toInt();
     QDir::setCurrent("/themes");
-    switch (selectedtheme) {
+    switch (2) {
     case 1:{
         DEB "main :: Loading light theme";
         QFile file(":light.qss");

+ 4 - 10
src/database/declarations.h

@@ -59,16 +59,10 @@ struct DataPosition {
     DataPosition(const DataPosition& other) = default;
     DataPosition& operator=(const DataPosition& other) = default;
 
-    // Compatibility with qDebug
-    QString debug() const
-    {
-        DEB "Table: " + tableName + "RowId: " + QString::number(rowId);
-        return QString();
-    }
-    operator QString() const
-    {
-        return debug();    //overload for compatibility with qDebug()
-    }
+    REPR(DataPosition,
+         "tableName=" << object.tableName << ", "
+         "rowId=" << object.rowId
+         )
 };
 
 // [F]:

+ 27 - 0
src/testing/adebug.h

@@ -5,4 +5,31 @@
 
 #define DEB qDebug() << __PRETTY_FUNCTION__ << "\t" <<
 
+/*!
+ * Representation macro for custom classes.
+ *
+ * Usage
+ * -----
+ * class Myclass {
+ *  ...
+ * 	REPR(MyClass,
+ *       "member1=" << object.member1 << ", "
+ *       "something2" << object.calculate()
+ *      )
+ * };
+ *
+ * MyClass mc;
+ * DEB mc;
+ *
+ * output:
+ * MyClass( member1= 3000 , something2= "A320" )
+ */
+#define REPR(cls, expr) \
+friend \
+QDebug operator<<(QDebug qdb, const cls& object) \
+{ \
+    qdb << #cls "(" << expr << ')'; \
+    return qdb; \
+}
+
 #endif