Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Network
Network File Sharing
Commits
1d40ba39
Commit
1d40ba39
authored
Aug 10, 2020
by
Harald Sitter
⛏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not refer to columns by their index
it's unreadable and also bound to break should the column indexes change
parent
68f34c00
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
12 deletions
+20
-12
samba/filepropertiesplugin/delegate.cpp
samba/filepropertiesplugin/delegate.cpp
+4
-3
samba/filepropertiesplugin/model.cpp
samba/filepropertiesplugin/model.cpp
+7
-6
samba/filepropertiesplugin/model.h
samba/filepropertiesplugin/model.h
+6
-1
samba/filepropertiesplugin/sambausershareplugin.cpp
samba/filepropertiesplugin/sambausershareplugin.cpp
+3
-2
No files found.
samba/filepropertiesplugin/delegate.cpp
View file @
1d40ba39
...
...
@@ -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
;
}
...
...
samba/filepropertiesplugin/model.cpp
View file @
1d40ba39
...
...
@@ -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
;
}
...
...
samba/filepropertiesplugin/model.h
View file @
1d40ba39
...
...
@@ -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
;
...
...
samba/filepropertiesplugin/sambausershareplugin.cpp
View file @
1d40ba39
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment