Commit 1d40ba39 authored by Harald Sitter's avatar Harald Sitter

do not refer to columns by their index

it's unreadable and also bound to break should the column indexes change
parent 68f34c00
......@@ -23,6 +23,7 @@
#include <KLocalizedString>
#include "delegate.h"
#include "model.h"
UserPermissionDelegate::UserPermissionDelegate(QObject *parent)
: QItemDelegate(parent)
......@@ -33,7 +34,7 @@ QWidget *UserPermissionDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & /* option */,
const QModelIndex &index) const
{
if (index.column() != 1) {
if (index.column() != UserPermissionModel::ColumnAccess) {
return nullptr;
}
......@@ -50,7 +51,7 @@ void UserPermissionDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
if (!comboBox || (index.column() != 1)) {
if (!comboBox || (index.column() != UserPermissionModel::ColumnAccess)) {
return;
}
......@@ -66,7 +67,7 @@ void UserPermissionDelegate::setModelData(QWidget *editor, QAbstractItemModel *m
const QModelIndex &index) const
{
QComboBox *comboBox = qobject_cast<QComboBox *>(editor);
if (!comboBox || (index.column() != 1)) {
if (!comboBox || (index.column() != UserPermissionModel::ColumnAccess)) {
return;
}
......
......@@ -22,6 +22,7 @@
#include <QFile>
#include <QRegularExpression>
#include <QMetaEnum>
#include <sys/stat.h>
......@@ -107,16 +108,16 @@ int UserPermissionModel::rowCount(const QModelIndex &parent) const
int UserPermissionModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return 2;
return QMetaEnum::fromType<Column>().keyCount();
}
QVariant UserPermissionModel::data(const QModelIndex &index, int role) const
{
if ((role == Qt::DisplayRole) && (index.column() == 0)) {
if ((role == Qt::DisplayRole) && (index.column() == ColumnUsername)) {
return QVariant(m_userList.at(index.row()));
}
if ((role == Qt::DisplayRole || role == Qt::EditRole) && (index.column() == 1)) {
if ((role == Qt::DisplayRole || role == Qt::EditRole) && (index.column() == ColumnAccess)) {
QMap<QString, QVariant>::ConstIterator itr;
for (itr = m_usersAcl.constBegin(); itr != m_usersAcl.constEnd(); ++itr) {
if (itr.key().endsWith(m_userList.at(index.row()))) {
......@@ -130,11 +131,11 @@ QVariant UserPermissionModel::data(const QModelIndex &index, int role) const
Qt::ItemFlags UserPermissionModel::flags(const QModelIndex &index) const
{
if (index.column() == 0) {
if (index.column() == ColumnUsername) {
return Qt::ItemIsSelectable;
}
if (index.column() == 1) {
if (index.column() == ColumnAccess) {
return (Qt::ItemIsEnabled | Qt::ItemIsEditable);
}
......@@ -143,7 +144,7 @@ Qt::ItemFlags UserPermissionModel::flags(const QModelIndex &index) const
bool UserPermissionModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if ((role != Qt::EditRole) || (index.column() != 1)) {
if ((role != Qt::EditRole) || (index.column() != ColumnAccess)) {
return false;
}
......
......@@ -30,8 +30,13 @@ class KSambaShareData;
class UserPermissionModel : public QAbstractTableModel
{
Q_OBJECT
public:
enum Column {
ColumnUsername,
ColumnAccess
};
Q_ENUM(Column)
explicit UserPermissionModel(KSambaShareData &shareData, QObject *parent = nullptr);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
......
......@@ -146,7 +146,7 @@ SambaUserSharePlugin::SambaUserSharePlugin(QObject *parent, const QList<QVariant
});
for (int i = 0; i < model->rowCount(); ++i) {
propertiesUi.tableView->openPersistentEditor(model->index(i, 1, QModelIndex()));
propertiesUi.tableView->openPersistentEditor(model->index(i, UserPermissionModel::ColumnAccess, QModelIndex()));
}
if (!isSambaInstalled()) {
m_installSambaWidgets->show();
......@@ -224,7 +224,8 @@ void SambaUserSharePlugin::setupViews()
propertiesUi.tableView->setModel(model);
propertiesUi.tableView->setSelectionMode(QAbstractItemView::NoSelection);
propertiesUi.tableView->setItemDelegate(new UserPermissionDelegate(this));
propertiesUi.tableView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
propertiesUi.tableView->horizontalHeader()->setSectionResizeMode(UserPermissionModel::ColumnAccess,
QHeaderView::Stretch);
}
void SambaUserSharePlugin::load()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment