Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
System
Dolphin
Commits
af2baf80
Commit
af2baf80
authored
Dec 16, 2021
by
Kai Uwe Broulik
🍇
Browse files
Remove KStandardItem and KStandardItemModel
They were used by the custom places panel and are now unused.
parent
0603e18c
Pipeline
#122340
passed with stage
in 5 minutes and 21 seconds
Changes
7
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
af2baf80
...
...
@@ -74,11 +74,9 @@ target_sources(dolphinprivate PRIVATE
kitemviews/kitemlistwidget.cpp
kitemviews/kitemmodelbase.cpp
kitemviews/kitemset.cpp
kitemviews/kstandarditem.cpp
kitemviews/kstandarditemlistgroupheader.cpp
kitemviews/kstandarditemlistwidget.cpp
kitemviews/kstandarditemlistview.cpp
kitemviews/kstandarditemmodel.cpp
kitemviews/private/kdirectorycontentscounter.cpp
kitemviews/private/kdirectorycontentscounterworker.cpp
kitemviews/private/kfileitemclipboard.cpp
...
...
src/kitemviews/kstandarditem.cpp
deleted
100644 → 0
View file @
0603e18c
/*
* SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kstandarditem.h"
#include "kstandarditemmodel.h"
KStandardItem
::
KStandardItem
(
KStandardItem
*
parent
)
:
QObject
(
parent
),
m_model
(
nullptr
),
m_data
()
{
}
KStandardItem
::
KStandardItem
(
const
QString
&
text
,
KStandardItem
*
parent
)
:
QObject
(
parent
),
m_model
(
nullptr
),
m_data
()
{
setText
(
text
);
}
KStandardItem
::
KStandardItem
(
const
QString
&
icon
,
const
QString
&
text
,
KStandardItem
*
parent
)
:
QObject
(
parent
),
m_model
(
nullptr
),
m_data
()
{
setIcon
(
icon
);
setText
(
text
);
}
KStandardItem
::~
KStandardItem
()
{
}
void
KStandardItem
::
setText
(
const
QString
&
text
)
{
setDataValue
(
"text"
,
text
);
}
QString
KStandardItem
::
text
()
const
{
return
m_data
[
"text"
].
toString
();
}
void
KStandardItem
::
setIcon
(
const
QString
&
icon
)
{
setDataValue
(
"iconName"
,
icon
);
}
QString
KStandardItem
::
icon
()
const
{
return
m_data
[
"iconName"
].
toString
();
}
void
KStandardItem
::
setIconOverlays
(
const
QStringList
&
overlays
)
{
setDataValue
(
"iconOverlays"
,
overlays
);
}
QStringList
KStandardItem
::
iconOverlays
()
const
{
return
m_data
[
"iconOverlays"
].
toStringList
();
}
void
KStandardItem
::
setGroup
(
const
QString
&
group
)
{
setDataValue
(
"group"
,
group
);
}
QString
KStandardItem
::
group
()
const
{
return
m_data
[
"group"
].
toString
();
}
void
KStandardItem
::
setDataValue
(
const
QByteArray
&
role
,
const
QVariant
&
value
)
{
const
QVariant
previous
=
m_data
.
value
(
role
);
if
(
previous
==
value
)
{
return
;
}
m_data
.
insert
(
role
,
value
);
onDataValueChanged
(
role
,
value
,
previous
);
if
(
m_model
)
{
const
int
index
=
m_model
->
index
(
this
);
QSet
<
QByteArray
>
changedRoles
;
changedRoles
.
insert
(
role
);
m_model
->
onItemChanged
(
index
,
changedRoles
);
Q_EMIT
m_model
->
itemsChanged
(
KItemRangeList
()
<<
KItemRange
(
index
,
1
),
changedRoles
);
}
}
QVariant
KStandardItem
::
dataValue
(
const
QByteArray
&
role
)
const
{
return
m_data
[
role
];
}
void
KStandardItem
::
setData
(
const
QHash
<
QByteArray
,
QVariant
>&
values
)
{
const
QHash
<
QByteArray
,
QVariant
>
previous
=
m_data
;
m_data
=
values
;
onDataChanged
(
values
,
previous
);
}
QHash
<
QByteArray
,
QVariant
>
KStandardItem
::
data
()
const
{
return
m_data
;
}
void
KStandardItem
::
onDataValueChanged
(
const
QByteArray
&
role
,
const
QVariant
&
current
,
const
QVariant
&
previous
)
{
Q_UNUSED
(
role
)
Q_UNUSED
(
current
)
Q_UNUSED
(
previous
)
}
void
KStandardItem
::
onDataChanged
(
const
QHash
<
QByteArray
,
QVariant
>&
current
,
const
QHash
<
QByteArray
,
QVariant
>&
previous
)
{
Q_UNUSED
(
current
)
Q_UNUSED
(
previous
)
}
src/kitemviews/kstandarditem.h
deleted
100644 → 0
View file @
0603e18c
/*
* SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KSTANDARDITEM_H
#define KSTANDARDITEM_H
#include "dolphin_export.h"
#include <QByteArray>
#include <QHash>
#include <QObject>
#include <QSet>
#include <QVariant>
class
KStandardItemModel
;
/**
* @brief Represents and item of KStandardItemModel.
*
* Provides setter- and getter-methods for the most commonly
* used roles. It is possible to assign values for custom
* roles by using setDataValue().
*/
class
DOLPHIN_EXPORT
KStandardItem
:
public
QObject
{
Q_OBJECT
public:
explicit
KStandardItem
(
KStandardItem
*
parent
=
nullptr
);
explicit
KStandardItem
(
const
QString
&
text
,
KStandardItem
*
parent
=
nullptr
);
KStandardItem
(
const
QString
&
icon
,
const
QString
&
text
,
KStandardItem
*
parent
=
nullptr
);
~
KStandardItem
()
override
;
/**
* Sets the text for the "text"-role.
*/
void
setText
(
const
QString
&
text
);
QString
text
()
const
;
/**
* Sets the icon for the "iconName"-role.
*/
void
setIcon
(
const
QString
&
icon
);
QString
icon
()
const
;
void
setIconOverlays
(
const
QStringList
&
overlays
);
QStringList
iconOverlays
()
const
;
/**
* Sets the group for the "group"-role.
*/
void
setGroup
(
const
QString
&
group
);
QString
group
()
const
;
void
setDataValue
(
const
QByteArray
&
role
,
const
QVariant
&
value
);
QVariant
dataValue
(
const
QByteArray
&
role
)
const
;
void
setData
(
const
QHash
<
QByteArray
,
QVariant
>&
values
);
QHash
<
QByteArray
,
QVariant
>
data
()
const
;
protected:
virtual
void
onDataValueChanged
(
const
QByteArray
&
role
,
const
QVariant
&
current
,
const
QVariant
&
previous
);
virtual
void
onDataChanged
(
const
QHash
<
QByteArray
,
QVariant
>&
current
,
const
QHash
<
QByteArray
,
QVariant
>&
previous
);
private:
KStandardItemModel
*
m_model
;
QHash
<
QByteArray
,
QVariant
>
m_data
;
friend
class
KStandardItemModel
;
};
#endif
src/kitemviews/kstandarditemmodel.cpp
deleted
100644 → 0
View file @
0603e18c
/*
* SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kstandarditemmodel.h"
#include "kstandarditem.h"
KStandardItemModel
::
KStandardItemModel
(
QObject
*
parent
)
:
KItemModelBase
(
parent
),
m_items
(),
m_indexesForItems
()
{
}
KStandardItemModel
::~
KStandardItemModel
()
{
qDeleteAll
(
m_items
);
m_items
.
clear
();
m_indexesForItems
.
clear
();
}
void
KStandardItemModel
::
insertItem
(
int
index
,
KStandardItem
*
item
)
{
if
(
index
<
0
||
index
>
count
()
||
!
item
)
{
delete
item
;
return
;
}
if
(
!
m_indexesForItems
.
contains
(
item
))
{
item
->
m_model
=
this
;
m_items
.
insert
(
index
,
item
);
m_indexesForItems
.
insert
(
item
,
index
);
// Inserting an item requires to update the indexes
// afterwards from m_indexesForItems.
for
(
int
i
=
index
+
1
;
i
<
m_items
.
count
();
++
i
)
{
m_indexesForItems
.
insert
(
m_items
[
i
],
i
);
}
// TODO: no hierarchical items are handled yet
onItemInserted
(
index
);
Q_EMIT
itemsInserted
(
KItemRangeList
()
<<
KItemRange
(
index
,
1
));
}
}
void
KStandardItemModel
::
changeItem
(
int
index
,
KStandardItem
*
item
)
{
if
(
index
<
0
||
index
>=
count
()
||
!
item
)
{
delete
item
;
return
;
}
item
->
m_model
=
this
;
QSet
<
QByteArray
>
changedRoles
;
KStandardItem
*
oldItem
=
m_items
[
index
];
const
QHash
<
QByteArray
,
QVariant
>
oldData
=
oldItem
->
data
();
const
QHash
<
QByteArray
,
QVariant
>
newData
=
item
->
data
();
// Determine which roles have been changed
QHashIterator
<
QByteArray
,
QVariant
>
it
(
oldData
);
while
(
it
.
hasNext
())
{
it
.
next
();
const
QByteArray
role
=
it
.
key
();
const
QVariant
oldValue
=
it
.
value
();
if
(
newData
.
contains
(
role
)
&&
newData
.
value
(
role
)
!=
oldValue
)
{
changedRoles
.
insert
(
role
);
}
}
m_indexesForItems
.
remove
(
oldItem
);
delete
oldItem
;
oldItem
=
nullptr
;
m_items
[
index
]
=
item
;
m_indexesForItems
.
insert
(
item
,
index
);
onItemChanged
(
index
,
changedRoles
);
Q_EMIT
itemsChanged
(
KItemRangeList
()
<<
KItemRange
(
index
,
1
),
changedRoles
);
}
void
KStandardItemModel
::
removeItem
(
int
index
)
{
if
(
index
>=
0
&&
index
<
count
())
{
KStandardItem
*
item
=
m_items
[
index
];
m_indexesForItems
.
remove
(
item
);
m_items
.
removeAt
(
index
);
// Removing an item requires to update the indexes
// afterwards from m_indexesForItems.
for
(
int
i
=
index
;
i
<
m_items
.
count
();
++
i
)
{
m_indexesForItems
.
insert
(
m_items
[
i
],
i
);
}
onItemRemoved
(
index
,
item
);
item
->
deleteLater
();
item
=
nullptr
;
Q_EMIT
itemsRemoved
(
KItemRangeList
()
<<
KItemRange
(
index
,
1
));
// TODO: no hierarchical items are handled yet
}
}
void
KStandardItemModel
::
clear
()
{
int
size
=
m_items
.
size
();
m_items
.
clear
();
m_indexesForItems
.
clear
();
Q_EMIT
itemsRemoved
(
KItemRangeList
()
<<
KItemRange
(
0
,
size
));
}
KStandardItem
*
KStandardItemModel
::
item
(
int
index
)
const
{
if
(
index
<
0
||
index
>=
m_items
.
count
())
{
return
nullptr
;
}
return
m_items
[
index
];
}
int
KStandardItemModel
::
index
(
const
KStandardItem
*
item
)
const
{
return
m_indexesForItems
.
value
(
item
,
-
1
);
}
void
KStandardItemModel
::
appendItem
(
KStandardItem
*
item
)
{
insertItem
(
m_items
.
count
(),
item
);
}
int
KStandardItemModel
::
count
()
const
{
return
m_items
.
count
();
}
QHash
<
QByteArray
,
QVariant
>
KStandardItemModel
::
data
(
int
index
)
const
{
if
(
index
>=
0
&&
index
<
count
())
{
const
KStandardItem
*
item
=
m_items
[
index
];
if
(
item
)
{
return
item
->
data
();
}
}
return
QHash
<
QByteArray
,
QVariant
>
();
}
bool
KStandardItemModel
::
setData
(
int
index
,
const
QHash
<
QByteArray
,
QVariant
>&
values
)
{
Q_UNUSED
(
values
)
if
(
index
<
0
||
index
>=
count
())
{
return
false
;
}
return
true
;
}
QMimeData
*
KStandardItemModel
::
createMimeData
(
const
KItemSet
&
indexes
)
const
{
Q_UNUSED
(
indexes
)
return
nullptr
;
}
int
KStandardItemModel
::
indexForKeyboardSearch
(
const
QString
&
text
,
int
startFromIndex
)
const
{
Q_UNUSED
(
text
)
Q_UNUSED
(
startFromIndex
)
return
-
1
;
}
bool
KStandardItemModel
::
supportsDropping
(
int
index
)
const
{
Q_UNUSED
(
index
)
return
false
;
}
QString
KStandardItemModel
::
roleDescription
(
const
QByteArray
&
role
)
const
{
Q_UNUSED
(
role
)
return
QString
();
}
QList
<
QPair
<
int
,
QVariant
>
>
KStandardItemModel
::
groups
()
const
{
QList
<
QPair
<
int
,
QVariant
>
>
groups
;
const
QByteArray
role
=
sortRole
().
isEmpty
()
?
"group"
:
sortRole
();
bool
isFirstGroupValue
=
true
;
QString
groupValue
;
const
int
maxIndex
=
count
()
-
1
;
for
(
int
i
=
0
;
i
<=
maxIndex
;
++
i
)
{
const
QString
newGroupValue
=
m_items
.
at
(
i
)
->
dataValue
(
role
).
toString
();
if
(
newGroupValue
!=
groupValue
||
isFirstGroupValue
)
{
groupValue
=
newGroupValue
;
groups
.
append
(
QPair
<
int
,
QVariant
>
(
i
,
newGroupValue
));
isFirstGroupValue
=
false
;
}
}
return
groups
;
}
void
KStandardItemModel
::
onItemInserted
(
int
index
)
{
Q_UNUSED
(
index
)
}
void
KStandardItemModel
::
onItemChanged
(
int
index
,
const
QSet
<
QByteArray
>&
changedRoles
)
{
Q_UNUSED
(
index
)
Q_UNUSED
(
changedRoles
)
}
void
KStandardItemModel
::
onItemRemoved
(
int
index
,
KStandardItem
*
removedItem
)
{
Q_UNUSED
(
index
)
Q_UNUSED
(
removedItem
)
}
src/kitemviews/kstandarditemmodel.h
deleted
100644 → 0
View file @
0603e18c
/*
* SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KSTANDARDITEMMODEL_H
#define KSTANDARDITEMMODEL_H
#include "dolphin_export.h"
#include "kitemviews/kitemmodelbase.h"
#include <QHash>
#include <QList>
class
KStandardItem
;
/**
* @brief Model counterpart for KStandardItemListView.
*
* Allows to add items to the model in an easy way by the
* class KStandardItem.
*
* @see KStandardItem
*/
class
DOLPHIN_EXPORT
KStandardItemModel
:
public
KItemModelBase
{
Q_OBJECT
public:
explicit
KStandardItemModel
(
QObject
*
parent
=
nullptr
);
~
KStandardItemModel
()
override
;
/**
* Inserts the item \a item at the index \a index. If the index
* is equal to the number of items of the model, the item
* gets appended as last element. KStandardItemModel takes
* the ownership of the item. If the index is invalid, the item
* gets deleted.
*/
void
insertItem
(
int
index
,
KStandardItem
*
item
);
/**
* Changes the item on the index \a index to \a item.
* KStandardItemModel takes the ownership of the item. The
* old item gets deleted. If the index is invalid, the item
* gets deleted.
*/
void
changeItem
(
int
index
,
KStandardItem
*
item
);
void
removeItem
(
int
index
);
KStandardItem
*
item
(
int
index
)
const
;
int
index
(
const
KStandardItem
*
item
)
const
;
/**
* Convenience method for insertItem(count(), item).
*/
void
appendItem
(
KStandardItem
*
item
);
int
count
()
const
override
;
QHash
<
QByteArray
,
QVariant
>
data
(
int
index
)
const
override
;
bool
setData
(
int
index
,
const
QHash
<
QByteArray
,
QVariant
>&
values
)
override
;
QMimeData
*
createMimeData
(
const
KItemSet
&
indexes
)
const
override
;
int
indexForKeyboardSearch
(
const
QString
&
text
,
int
startFromIndex
=
0
)
const
override
;
bool
supportsDropping
(
int
index
)
const
override
;
QString
roleDescription
(
const
QByteArray
&
role
)
const
override
;
QList
<
QPair
<
int
,
QVariant
>
>
groups
()
const
override
;
virtual
void
clear
();
protected:
/**
* Is invoked after an item has been inserted and before the signal
* itemsInserted() gets emitted.
*/
virtual
void
onItemInserted
(
int
index
);
/**
* Is invoked after an item or one of its roles has been changed and
* before the signal itemsChanged() gets emitted.
*/
virtual
void
onItemChanged
(
int
index
,
const
QSet
<
QByteArray
>&
changedRoles
);
/**
* Is invoked after an item has been removed and before the signal
* itemsRemoved() gets emitted. The item \a removedItem has already
* been removed from the model and will get deleted after the
* execution of onItemRemoved().
*/
virtual
void
onItemRemoved
(
int
index
,
KStandardItem
*
removedItem
);
private:
QList
<
KStandardItem
*>
m_items
;
QHash
<
const
KStandardItem
*
,
int
>
m_indexesForItems
;
friend
class
KStandardItem
;
friend
class
KStandardItemModelTest
;
// For unit testing
};
#endif
src/tests/CMakeLists.txt
View file @
af2baf80
...
...
@@ -51,11 +51,6 @@ if (KF5Baloo_FOUND)
LINK_LIBRARIES dolphinprivate dolphinstatic Qt5::Test
)
endif
()
# KStandardItemModelTest
ecm_add_test
(
kstandarditemmodeltest.cpp
TEST_NAME kstandarditemmodeltest
LINK_LIBRARIES dolphinprivate dolphinstatic Qt5::Test
)
# ViewPropertiesTest
ecm_add_test
(
viewpropertiestest.cpp testdir.cpp
TEST_NAME viewpropertiestest
...
...
src/tests/kstandarditemmodeltest.cpp
deleted
100644 → 0
View file @
0603e18c
/*
* SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
* SPDX-FileCopyrightText: 2011 Frank Reininghaus <frank78ac@googlemail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "dolphindebug.h"
#include "kitemviews/kstandarditem.h"
#include "kitemviews/kstandarditemmodel.h"
#include <QStandardPaths>
#include <QTest>
class
KStandardItemModelTest
:
public
QObject
{
Q_OBJECT
private
Q_SLOTS
:
void
initTestCase
();
void
init
();
void
cleanup
();
void
testNewItems
();
void
testRemoveItems
();
private:
bool
isModelConsistent
()
const
;
private:
KStandardItemModel
*
m_model
;
};
void
KStandardItemModelTest
::
initTestCase
()
{
QStandardPaths
::
setTestModeEnabled
(
true
);
}
void
KStandardItemModelTest
::
init
()
{
m_model
=
new
KStandardItemModel
();
}
void
KStandardItemModelTest
::
cleanup
()
{
delete
m_model
;
m_model
=
nullptr
;
}
void
KStandardItemModelTest
::
testNewItems
()