Logo    
KDWinUtils
Helper library for MFC to Qt migration
Loading...
Searching...
No Matches
kstringarray.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** This file is part of KDWinutils, KDAB's MFC to Qt migration tool.
4**
5** Copyright (C) 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6** All rights reserved.
7**
8** This file is intended solely for use by the migration tools and services
9** provided by Klarälvdalens Datakonsult AB.
10**
11** Any other use or distribution of this software that is not otherwise agreed
12** upon in writing and signed by an authorized representative of Klarälvdalens
13** Datakonsult AB, KDAB (USA) LLC, KDAB (Deutschland) GmbH & Co. K.G.,
14** KDAB (France) SAS, KDAB (UK), Ltd., or any future subsidiary of Klarälvdalens
15** Datakonsult AB is hereby prohibited.
16**
17** Contact info@kdab.com if any conditions stated above are unclear to you.
18**
19****************************************************************************/
20
21#pragma once
22
24#include "kstring.h"
25
26#include <QStringList>
27
29
38class KDWINUTILS_EXPORT KStringArray : public QList<KString>
39{
40public:
42 using QList<KString>::QList;
43
44 // QStringList CString specific methods
45 /* implicit */ KStringArray(const QStringList &strList);
46 using QList<KString>::operator=;
47 KStringArray &operator=(const QStringList &strList);
48 QStringList toQStringList() const;
49 /* implicit */ operator QStringList() const;
50
51#ifdef KDWINUTILS_WITHMFC
52 // CStringArray specific methods, available only on Windows with MFC set
53 // Note: CStringArray is not copyable, nor movable, so we cannot provide any conversion operators
54 // and it doesn't make sense to add a constructor from CStringArray either.
56 void Copy(const CStringArray &strArray);
57#endif // KDWINUTILS_WITHMFC
58
59 // MFC API from here on
61
62 int Add(const KString &str);
63
65 int Append(const KStringArray &src);
66
68 void Copy(const KStringArray &src);
69
71 QString &ElementAt(int nIndex);
72
74 void FreeExtra();
75
77 const QString &GetAt(int nIndex) const;
78
80 int GetCount() const;
81
83 int GetSize() const;
84
86 int GetUpperBound() const;
87
89 void InsertAt(int nIndex, const KString &newElement, int nCount = 1);
90
92 void InsertAt(int nStartIndex, const KStringArray &pNewArray);
93
95 bool IsEmpty() const;
96
98 void RemoveAll();
99
101 void RemoveAt(int nIndex, int nCount = 1);
102
104 void SetAt(int nIndex, const KString &newElement);
105
107 void SetAtGrow(int nIndex, const QString &newElement);
108
110 void SetSize(int nNewSize, int nGrowBy = -1);
111};
112
The KStringArray class provides a list of strings.
Definition kstringarray.h:39
bool IsEmpty() const
Determines if the array is empty.
KStringArray & operator=(const QStringList &strList)
void RemoveAt(int nIndex, int nCount=1)
Removes an element at a specific index.
void Copy(const CStringArray &strArray)
Copies another array to the array; grows the array if necessary.
QStringList toQStringList() const
void FreeExtra()
Frees all unused memory above the current upper bound.
void InsertAt(int nIndex, const KString &newElement, int nCount=1)
Inserts an element at a specified index.
int GetCount() const
Gets the number of elements in this array.
void SetAtGrow(int nIndex, const QString &newElement)
Sets the value for a given index; grows the array if necessary.
int GetUpperBound() const
Returns the largest valid index.
const QString & GetAt(int nIndex) const
Returns the value at a given index.
void SetSize(int nNewSize, int nGrowBy=-1)
int Add(const KString &str)
Adds an element to the end of the array; grows the array if necessary.
int GetSize() const
Gets the number of elements in this array.
void InsertAt(int nStartIndex, const KStringArray &pNewArray)
Inserts all the elements in another array at a specified index.
void SetAt(int nIndex, const KString &newElement)
Sets the value for a given index; array not allowed to grow.
void RemoveAll()
Removes all the elements from this array.
QString & ElementAt(int nIndex)
Returns a temporary reference to the element pointer within the array.
void Copy(const KStringArray &src)
Copies another array to the array; grows the array if necessary.
KStringArray(const QStringList &strList)
int Append(const KStringArray &src)
Appends another array to the array; grows the array if necessary.
The KString class provides a Unicode character string.
Definition kstring.h:45
#define KDWINUTILS_EXPORT
Definition kdwinutils_export.h:31
#define KDWINUTILS_BEGIN_NAMESPACE
Definition kdwinutils_global.h:27
#define KDWINUTILS_END_NAMESPACE
Definition kdwinutils_global.h:28