-
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.
- Loading branch information
Showing
9 changed files
with
168 additions
and
13 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,46 @@ | ||
#include "colormodel.h" | ||
|
||
#include <screencolormanager.h> | ||
|
||
struct ColorModelPrivate { | ||
}; | ||
|
||
ColorModel::ColorModel(QObject* parent) : | ||
QAbstractListModel(parent), d{new ColorModelPrivate()} { | ||
} | ||
|
||
ColorModel::~ColorModel() { | ||
delete d; | ||
} | ||
|
||
int ColorModel::rowCount(const QModelIndex& parent) const { | ||
// For list models only the root node (an invalid parent) should return the list's size. For all | ||
// other (valid) parents, rowCount() should return 0 so that it does not become a tree model. | ||
if (parent.isValid()) | ||
return 0; | ||
|
||
// FIXME: Implement me! | ||
return ScreenColorManager::definitions().length(); | ||
} | ||
|
||
QVariant ColorModel::data(const QModelIndex& index, int role) const { | ||
if (!index.isValid()) | ||
return QVariant(); | ||
|
||
auto definition = ScreenColorManager::definitions().value(index.row()); | ||
switch (role) { | ||
case Description: | ||
return ScreenColorManager::name(definition); | ||
case Identifier: | ||
return definition; | ||
} | ||
|
||
return QVariant(); | ||
} | ||
|
||
QHash<int, QByteArray> ColorModel::roleNames() const { | ||
return { | ||
{Description, "description"}, | ||
{Identifier, "identifier" } | ||
}; | ||
} |
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,30 @@ | ||
#ifndef COLORMODEL_H | ||
#define COLORMODEL_H | ||
|
||
#include <QAbstractListModel> | ||
#include <QQmlComponent> | ||
|
||
struct ColorModelPrivate; | ||
class ColorModel : public QAbstractListModel { | ||
Q_OBJECT | ||
QML_ELEMENT | ||
|
||
public: | ||
explicit ColorModel(QObject* parent = nullptr); | ||
~ColorModel(); | ||
|
||
enum ColorRoles { | ||
Description = Qt::DisplayRole, | ||
Identifier = Qt::UserRole | ||
}; | ||
|
||
// Basic functionality: | ||
int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
private: | ||
ColorModelPrivate* d; | ||
}; | ||
|
||
#endif // COLORMODEL_H |
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