[kcms/cursor] Untabelify model

We don't need a table model here, a list model is enough
wilder-5.25
Nicolas Fella 4 years ago
parent 628f7d7cfa
commit 143f946ba6
  1. 2
      kcms/cursortheme/kcmcursortheme.cpp
  2. 43
      kcms/cursortheme/xcursor/thememodel.cpp
  3. 15
      kcms/cursortheme/xcursor/thememodel.h

@ -67,7 +67,7 @@ CursorThemeConfig::CursorThemeConfig(QObject *parent, const KPluginMetaData &dat
m_themeProxyModel->setSourceModel(m_themeModel); m_themeProxyModel->setSourceModel(m_themeModel);
// sort ordering is already case-insensitive; match that for filtering too // sort ordering is already case-insensitive; match that for filtering too
m_themeProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_themeProxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
m_themeProxyModel->sort(NameColumn, Qt::AscendingOrder); m_themeProxyModel->sort(0, Qt::AscendingOrder);
m_sizesModel = new QStandardItemModel(this); m_sizesModel = new QStandardItemModel(this);

@ -28,7 +28,7 @@
#endif #endif
CursorThemeModel::CursorThemeModel(QObject *parent) CursorThemeModel::CursorThemeModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractListModel(parent)
{ {
insertThemes(); insertThemes();
} }
@ -41,7 +41,7 @@ CursorThemeModel::~CursorThemeModel()
QHash<int, QByteArray> CursorThemeModel::roleNames() const QHash<int, QByteArray> CursorThemeModel::roleNames() const
{ {
QHash<int, QByteArray> roleNames = QAbstractTableModel::roleNames(); QHash<int, QByteArray> roleNames = QAbstractListModel::roleNames();
roleNames[CursorTheme::DisplayDetailRole] = "description"; roleNames[CursorTheme::DisplayDetailRole] = "description";
roleNames[CursorTheme::IsWritableRole] = "isWritable"; roleNames[CursorTheme::IsWritableRole] = "isWritable";
roleNames[CursorTheme::PendingDeletionRole] = "pendingDeletion"; roleNames[CursorTheme::PendingDeletionRole] = "pendingDeletion";
@ -59,30 +59,6 @@ void CursorThemeModel::refreshList()
insertThemes(); insertThemes();
} }
QVariant CursorThemeModel::headerData(int section, Qt::Orientation orientation, int role) const
{
// Only provide text for the headers
if (role != Qt::DisplayRole)
return QVariant();
// Horizontal header labels
if (orientation == Qt::Horizontal) {
switch (section) {
case NameColumn:
return i18n("Name");
case DescColumn:
return i18n("Description");
default:
return QVariant();
}
}
// Numbered vertical header labels
return QString::number(section);
}
QVariant CursorThemeModel::data(const QModelIndex &index, int role) const QVariant CursorThemeModel::data(const QModelIndex &index, int role) const
{ {
if (!index.isValid() || index.row() < 0 || index.row() >= list.count()) if (!index.isValid() || index.row() < 0 || index.row() >= list.count())
@ -92,24 +68,15 @@ QVariant CursorThemeModel::data(const QModelIndex &index, int role) const
// Text label // Text label
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
switch (index.column()) { return theme->title();
case NameColumn:
return theme->title();
case DescColumn:
return theme->description();
default:
return QVariant();
}
} }
// Description for the first name column // Description for the first name column
if (role == CursorTheme::DisplayDetailRole && index.column() == NameColumn) if (role == CursorTheme::DisplayDetailRole)
return theme->description(); return theme->description();
// Icon for the name column // Icon for the name column
if (role == Qt::DecorationRole && index.column() == NameColumn) if (role == Qt::DecorationRole)
return theme->icon(); return theme->icon();
if (role == CursorTheme::IsWritableRole) { if (role == CursorTheme::IsWritableRole) {

@ -12,12 +12,6 @@
class QDir; class QDir;
class CursorTheme; class CursorTheme;
// The two TableView/TreeView columns provided by the model
enum Columns {
NameColumn = 0,
DescColumn,
};
/** /**
* The CursorThemeModel class provides a model for all locally installed * The CursorThemeModel class provides a model for all locally installed
* Xcursor themes, and the KDE/Qt legacy bitmap theme. * Xcursor themes, and the KDE/Qt legacy bitmap theme.
@ -43,7 +37,7 @@ enum Columns {
* Calling defaultIndex() will return the index of the theme Xcursor * Calling defaultIndex() will return the index of the theme Xcursor
* will use if the user hasn't explicitly configured a cursor theme. * will use if the user hasn't explicitly configured a cursor theme.
*/ */
class CursorThemeModel : public QAbstractTableModel class CursorThemeModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
@ -51,9 +45,7 @@ public:
explicit CursorThemeModel(QObject *parent = nullptr); explicit CursorThemeModel(QObject *parent = nullptr);
~CursorThemeModel() override; ~CursorThemeModel() override;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
inline int columnCount(const QModelIndex &parent = QModelIndex()) const override;
inline int rowCount(const QModelIndex &parent = QModelIndex()) const override; inline int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
@ -96,8 +88,3 @@ int CursorThemeModel::rowCount(const QModelIndex &) const
{ {
return list.count(); return list.count();
} }
int CursorThemeModel::columnCount(const QModelIndex &) const
{
return 2;
}

Loading…
Cancel
Save