Ver Fonte

Enable QStringBuilder globally

closes #56

QStringBuilder enabled in cmake and qmake config files. Code adjusted, works fine now. 
Wiki updated to include string usage guidelines.
Felix Turo há 4 anos atrás
pai
commit
5f91c160ff
4 ficheiros alterados com 23 adições e 3 exclusões
  1. 3 0
      CMakeLists.txt
  2. 13 0
      docs/wiki/wiki_coding_style.md
  3. 1 1
      openPilotLog.pro
  4. 6 2
      src/database/adatabase.cpp

+ 3 - 0
CMakeLists.txt

@@ -13,6 +13,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
 set(QT_MIN_VERSION "5.5.1")
 
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_USE_QSTRINGBUILDER")
+MESSAGE ("Enabling QStringBuilder")
+
 find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
 find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Sql Network REQUIRED)
 

+ 13 - 0
docs/wiki/wiki_coding_style.md

@@ -18,6 +18,19 @@ See https://wiki.qt.io/Qt_Coding_Style for general code style guidelines.
 |Type Alias|follow Qt Convention|`using NewType = QMap<QString, int>`|
 
 
+## Strings in openPilotLog
+
+Aim to construct and use strings in the most efficient way. 
+
+- For all user-facing string use [tr()](), so that the app is translatable.
+
+- Use [QStringLiteral](https://doc-snapshots.qt.io/qt6-dev/qstring.html#QStringLiteral) where possible, except when using a function that has a `char *` overload.
+
+- For string comparisons using the `==` operator, use [QLatin1String](https://wiki.qt.io/Using_QString_Effectively)
+
+- For concatenations, openPilotLog uses [QStringBuilder](https://doc-snapshots.qt.io/qt6-dev/qstring.html#more-efficient-string-construction) globally, so the `+` operator can be used.
+- (Debug etc. can be  `char *`, `QString` or anything else)
+
 ## Examples
 
 ```c++

+ 1 - 1
openPilotLog.pro

@@ -14,7 +14,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
 # In order to do so, uncomment the following line.
 # You can also select to disable deprecated APIs only up to a certain version of Qt.
 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
-QMAKE_CXXFLAGS += -Wno-deprecated-copy # see https://bugreports.qt.io/browse/QTBUG-75210
+DEFINES *= QT_USE_QSTRINGBUILDER
 
 # [G]: need to fix this. There must be a src/* command or smth
 SOURCES += \

+ 6 - 2
src/database/adatabase.cpp

@@ -199,13 +199,17 @@ bool ADatabase::removeMany(QList<DataPosition> data_position_list)
             lastError = QString();
             return true;
         } else {
-            lastError = "Transaction unsuccessful (Interrupted). Error count: " + QString::number(errorCount);
+            lastError = ADatabaseError(
+                        "Transaction unsuccessful (Interrupted). Error count: "
+                        + QString::number(errorCount));
             return false;
         }
     } else {
         query.prepare(QStringLiteral("ROLLBACK"));
         query.exec();
-        lastError = "Transaction unsuccessful (no changes have been made). Error count: " + QString::number(errorCount);
+        lastError = ADatabaseError(
+                    "Transaction unsuccessful (no changes have been made). Error count: "
+                    + QString::number(errorCount));
         return false;
     }
 }