From dfc8e6ed7b68be4a16578f738591ccda0e714d76 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sun, 5 Jun 2022 20:54:44 +0200 Subject: [PATCH] Make Profile::DefaultPropertyNames a vector instead of built-in array A vector doesn't decay to pointer, so we can iterate over it with range-for in Profile and ProfileReader/Writer without using pointers to array elements, and a while loop that checks for the special element at the end of the array to stop the loop. Also remove that dud element at the end of DefaultPropertyNames. std::array is a viable option, but the downside is we'd have to specify the number of elements in it (as that's part of its type), and keeping that number in sync when adding new properties could be problematic. --- src/profile/Profile.cpp | 8 +++----- src/profile/Profile.h | 4 +++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/profile/Profile.cpp b/src/profile/Profile.cpp index 00874f7c..f49cac6a 100644 --- a/src/profile/Profile.cpp +++ b/src/profile/Profile.cpp @@ -40,7 +40,7 @@ static const char CURSOR_GROUP[] = "Cursor Options"; static const char INTERACTION_GROUP[] = "Interaction Options"; static const char ENCODING_GROUP[] = "Encoding Options"; -const Profile::PropertyInfo Profile::DefaultPropertyNames[] = { +const std::vector Profile::DefaultPropertyNames = { // General {Path, "Path", nullptr, QVariant::String}, {Name, "Name", GENERAL_GROUP, QVariant::String}, @@ -135,10 +135,8 @@ const Profile::PropertyInfo Profile::DefaultPropertyNames[] = { // Encoding , - {DefaultEncoding, "DefaultEncoding", ENCODING_GROUP, QVariant::String} - - , - {static_cast(0), nullptr, nullptr, QVariant::Invalid}}; + {DefaultEncoding, "DefaultEncoding", ENCODING_GROUP, QVariant::String}, +}; QHash Profile::PropertyInfoByName; diff --git a/src/profile/Profile.h b/src/profile/Profile.h index b7c25189..154c3a5c 100644 --- a/src/profile/Profile.h +++ b/src/profile/Profile.h @@ -17,6 +17,8 @@ #include #include +#include + // Konsole #include "konsoleprofile_export.h" @@ -781,7 +783,7 @@ private: const char *group; QVariant::Type type; }; - static const PropertyInfo DefaultPropertyNames[]; + static const std::vector DefaultPropertyNames; }; inline bool Profile::canInheritProperty(Property p)