-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Impl] Use StringVectorModel to provide code completions
StringVectorModel: - Like QStringListModel, but utilize QVector<QString> instead.
- Loading branch information
Showing
7 changed files
with
96 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "stringvectormodel.h" | ||
|
||
StringVectorModel::StringVectorModel(QObject *parent) | ||
: QAbstractListModel{parent} { | ||
} | ||
|
||
StringVectorModel::StringVectorModel(const StringVector &vec, QObject *parent) | ||
: QAbstractListModel{parent}, m_vector{vec} { | ||
} | ||
|
||
int StringVectorModel::rowCount(const QModelIndex &parent) const { | ||
return m_vector.size(); | ||
} | ||
|
||
int StringVectorModel::columnCount(const QModelIndex &parent) const { | ||
return 1; | ||
} | ||
|
||
QVariant StringVectorModel::data(const QModelIndex &index, int role) const { | ||
if (role == Qt::DisplayRole || role == Qt::EditRole) { | ||
return m_vector.value(index.row(), QString()); | ||
} else { | ||
return {}; | ||
} | ||
} | ||
|
||
StringVector StringVectorModel::vector() const { | ||
return m_vector; | ||
} | ||
|
||
void StringVectorModel::setVector(const StringVector &newVector) { | ||
beginResetModel(); | ||
m_vector = newVector; | ||
endResetModel(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef STRINGVECTORMODEL_H | ||
#define STRINGVECTORMODEL_H | ||
|
||
#include <QAbstractListModel> | ||
|
||
using StringVector = QVector<QString>; | ||
|
||
class StringVectorModel : public QAbstractListModel { | ||
Q_OBJECT | ||
public: | ||
explicit StringVectorModel( | ||
QObject *parent = nullptr); | ||
explicit StringVectorModel(const StringVector &vec, | ||
QObject *parent = nullptr); | ||
|
||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
int columnCount(const QModelIndex &parent = QModelIndex()) const override; | ||
QVariant data(const QModelIndex &index, | ||
int role = Qt::DisplayRole) const override; | ||
|
||
StringVector vector() const; | ||
void setVector(const StringVector &newVector); | ||
|
||
private: | ||
StringVector m_vector; | ||
}; | ||
|
||
#endif // STRINGVECTORMODEL_H |