@@ -111,50 +111,36 @@ class UriValue {
111
111
QString mediaType;
112
112
};
113
113
114
- struct ItemBase {
114
+ using UriOrText = std::variant<QUrl, QString>;
115
+ using TimeZone = std::variant<QUrl, QString, int >;
116
+ using Historical = std::variant<QDateTime, QDate, QTime, QString>;
117
+
118
+ template <typename T> struct ItemBase {
115
119
Parameters parameters;
120
+ T data;
116
121
};
117
122
118
- template <typename T> struct Item : public ItemBase {
119
- T data;
120
- operator QString () const { return data; }
121
- operator QDate () const { return {} ; }
123
+ template <typename T> struct Item : public ItemBase <T> {
124
+ operator QString () const { return this -> data ; } // maybe convertible by Qt means
125
+ operator QDate () const { return QDate ( this -> data ) ; }
126
+ operator QUrl () const { return QUrl ( this -> data ) ; }
122
127
};
123
128
124
- template <> struct Item <QDate> : public ItemBase {
125
- QDate data;
129
+ template <> struct Item <QDate> : public ItemBase<QDate> {
126
130
operator QString () const { return data.toString (Qt::ISODate); }
127
131
operator QDate () const { return data; }
128
132
};
129
133
130
- template <> struct Item <QDateTime> : public ItemBase {
131
- QDateTime data;
134
+ template <> struct Item <QDateTime> : public ItemBase<QDateTime> {
132
135
operator QString () const { return data.toString (Qt::ISODate); }
133
136
operator QDate () const { return data.date (); }
134
137
};
135
138
136
- template <> struct Item <QStringList> : public ItemBase {
137
- QStringList data;
139
+ template <> struct Item <QStringList> : public ItemBase<QStringList> {
138
140
operator QString () const { return data.value (0 ); }
139
141
};
140
142
141
- using UriOrText = std::variant<QUrl, QString>;
142
- using TimeZone = std::variant<QUrl, QString, int >;
143
- using Historical = std::variant<QDateTime, QDate, QTime, QString>;
144
-
145
- using PStringList = Item<QStringList>;
146
- using PString = Item<QString>;
147
- using PUri = Item<QUrl>;
148
- using PDate = Item<QDate>;
149
- using PAdvUri = Item<UriValue>;
150
- using PAddress = Item<Address>;
151
- using PNames = Item<Names>;
152
- using PUriOrText = Item<UriOrText>;
153
- using PTimeZone = Item<TimeZone>;
154
- using PHistorical = Item<Historical>;
155
-
156
- template <> struct Item <Historical> : public ItemBase {
157
- Historical data;
143
+ template <> struct Item <Historical> : public ItemBase<Historical> {
158
144
operator QString () const
159
145
{
160
146
return std::visit (
@@ -186,6 +172,33 @@ template <> struct Item<Historical> : public ItemBase {
186
172
}
187
173
};
188
174
175
+ template <> struct Item <UriOrText> : public ItemBase<UriOrText> {
176
+ operator QString () const
177
+ {
178
+ return std::visit (
179
+ [this ](auto const &v) {
180
+ using Tv = std::decay_t <decltype (v)>;
181
+ if constexpr (std::is_same_v<Tv, QString>) {
182
+ return v;
183
+ } else {
184
+ return v.toString ();
185
+ }
186
+ },
187
+ data);
188
+ }
189
+ };
190
+
191
+ using PStringList = Item<QStringList>;
192
+ using PString = Item<QString>;
193
+ using PUri = Item<QUrl>;
194
+ using PDate = Item<QDate>;
195
+ using PAdvUri = Item<UriValue>;
196
+ using PAddress = Item<Address>;
197
+ using PNames = Item<Names>;
198
+ using PUriOrText = Item<UriOrText>;
199
+ using PTimeZone = Item<TimeZone>;
200
+ using PHistorical = Item<Historical>;
201
+
189
202
template <typename T> class TaggedList : public QList <T> {
190
203
public:
191
204
using item_type = T;
@@ -199,7 +212,8 @@ template <typename T> class TaggedList : public QList<T> {
199
212
*this , [](auto const &a, auto const &b) { return a.parameters .pref > b.parameters .pref ; });
200
213
}
201
214
202
- operator QString () const { return preferred ().data ; }
215
+ operator QString () const { return preferred (); }
216
+ operator QUrl () const { return preferred (); }
203
217
};
204
218
205
219
template <> class TaggedList <PAdvUri> : public QList<PAdvUri> {
@@ -221,12 +235,7 @@ template <> class TaggedList<PAdvUri> : public QList<PAdvUri> {
221
235
}
222
236
};
223
237
224
- class TaggedListStringList : public TaggedList <PStringList> {
225
- public:
226
- operator QString () const { return preferred ().data .value (0 ); }
227
- };
228
-
229
- using PStringLists = TaggedListStringList;
238
+ using PStringLists = TaggedList<PStringList>;
230
239
using PStrings = TaggedList<PString>;
231
240
using PUris = TaggedList<PUri>;
232
241
using PAdvUris = TaggedList<PAdvUri>;
0 commit comments