-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6d778b
commit d8e28f7
Showing
9 changed files
with
241 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
// STL headers | ||
#include <string> | ||
|
||
namespace kemai { | ||
|
||
struct Profile | ||
{ | ||
std::string name; | ||
std::string host; | ||
std::string token; | ||
}; | ||
|
||
} // namespace kemai |
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,52 @@ | ||
#include "profile.h" | ||
|
||
// magic_enum headers | ||
#include <magic_enum/magic_enum.hpp> | ||
|
||
namespace kemai { | ||
|
||
ProfileModel::ProfileModel(QObject* parent) : QAbstractListModel(parent) {} | ||
|
||
ProfileModel::~ProfileModel() = default; | ||
|
||
void ProfileModel::setProfiles(const std::vector<Profile>& profiles) | ||
{ | ||
beginResetModel(); | ||
m_profiles = profiles; | ||
endResetModel(); | ||
} | ||
|
||
int ProfileModel::rowCount(const QModelIndex& parent) const | ||
{ | ||
return static_cast<int>(m_profiles.size()); | ||
} | ||
|
||
QVariant ProfileModel::data(const QModelIndex& index, int role) const | ||
{ | ||
if (!index.isValid() || index.row() > m_profiles.size()) | ||
{ | ||
return {}; | ||
} | ||
|
||
const auto& profile = m_profiles[index.row()]; | ||
switch (static_cast<ProfileRole>(role)) | ||
{ | ||
case ProfileRole::Name: | ||
return QString::fromStdString(profile.name); | ||
case ProfileRole::Host: | ||
return QString::fromStdString(profile.host); | ||
case ProfileRole::Token: | ||
return QString::fromStdString(profile.token); | ||
default: | ||
return {}; | ||
} | ||
} | ||
|
||
QHash<int, QByteArray> ProfileModel::roleNames() const | ||
{ | ||
return {{magic_enum::enum_integer(ProfileRole::Name), "name"}, | ||
{magic_enum::enum_integer(ProfileRole::Host), "host"}, | ||
{magic_enum::enum_integer(ProfileRole::Token), "token"}}; | ||
} | ||
|
||
} // namespace kemai |
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,39 @@ | ||
#pragma once | ||
|
||
// STL headers | ||
#include <vector> | ||
|
||
// Qt headers | ||
#include <QAbstractListModel> | ||
|
||
// Project headers | ||
#include <data/profile.h> | ||
|
||
namespace kemai { | ||
|
||
class ProfileModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
enum class ProfileRole | ||
{ | ||
Name = Qt::UserRole + 1, | ||
Host, | ||
Token | ||
}; | ||
|
||
explicit ProfileModel(QObject* parent = nullptr); | ||
~ProfileModel() override; | ||
|
||
void setProfiles(const std::vector<Profile>& profiles); | ||
|
||
int rowCount(const QModelIndex& parent) const override; | ||
QVariant data(const QModelIndex& index, int role) const override; | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
private: | ||
std::vector<Profile> m_profiles; | ||
}; | ||
|
||
} // namespace kemai |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.