mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 00:41:23 +00:00
Places Panel: Fix implementation issues when hiding items
This commit is contained in:
parent
d76b113ad1
commit
f158bf097a
|
@ -1049,6 +1049,12 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In case if the first item of a group has been removed, the group header
|
||||||
|
// must be applied to the next visible item.
|
||||||
|
if (m_grouped && index < m_model->count()) {
|
||||||
|
updateGroupHeaderForWidget(m_visibleItems.value(index));
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasMultipleRanges) {
|
if (!hasMultipleRanges) {
|
||||||
// The decrease-layout-size optimization in KItemListView::slotItemsInserted()
|
// The decrease-layout-size optimization in KItemListView::slotItemsInserted()
|
||||||
// assumes an updated geometry. If items are removed during an active transaction,
|
// assumes an updated geometry. If items are removed during an active transaction,
|
||||||
|
|
|
@ -89,12 +89,15 @@ void PlacesItemModel::setItemHidden(int index, bool hide)
|
||||||
KStandardItem* shownItem = this->item(index);
|
KStandardItem* shownItem = this->item(index);
|
||||||
shownItem->setDataValue("isHidden", hide);
|
shownItem->setDataValue("isHidden", hide);
|
||||||
if (!m_hiddenItemsShown && hide) {
|
if (!m_hiddenItemsShown && hide) {
|
||||||
|
const int newIndex = hiddenIndex(index);
|
||||||
KStandardItem* hiddenItem = new KStandardItem(*shownItem);
|
KStandardItem* hiddenItem = new KStandardItem(*shownItem);
|
||||||
removeItem(index);
|
removeItem(index);
|
||||||
index = hiddenIndex(index);
|
m_hiddenItems.insert(newIndex, hiddenItem);
|
||||||
Q_ASSERT(!m_hiddenItems[index]);
|
|
||||||
m_hiddenItems[index] = hiddenItem;
|
|
||||||
}
|
}
|
||||||
|
#ifdef PLACESITEMMODEL_DEBUG
|
||||||
|
kDebug() << "Changed hide-state from" << index << "to" << hide;
|
||||||
|
showModelState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +175,11 @@ QAction* PlacesItemModel::tearDownAction(int index) const
|
||||||
|
|
||||||
void PlacesItemModel::onItemInserted(int index)
|
void PlacesItemModel::onItemInserted(int index)
|
||||||
{
|
{
|
||||||
m_hiddenItems.insert(hiddenIndex(index), 0);
|
if (index == count() - 1) {
|
||||||
|
m_hiddenItems.append(0);
|
||||||
|
} else {
|
||||||
|
m_hiddenItems.insert(hiddenIndex(index), 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacesItemModel::onItemRemoved(int index)
|
void PlacesItemModel::onItemRemoved(int index)
|
||||||
|
@ -180,6 +187,10 @@ void PlacesItemModel::onItemRemoved(int index)
|
||||||
const int removeIndex = hiddenIndex(index);
|
const int removeIndex = hiddenIndex(index);
|
||||||
Q_ASSERT(!m_hiddenItems[removeIndex]);
|
Q_ASSERT(!m_hiddenItems[removeIndex]);
|
||||||
m_hiddenItems.removeAt(removeIndex);
|
m_hiddenItems.removeAt(removeIndex);
|
||||||
|
#ifdef PLACESITEMMODEL_DEBUG
|
||||||
|
kDebug() << "Removed item" << index;
|
||||||
|
showModelState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacesItemModel::loadBookmarks()
|
void PlacesItemModel::loadBookmarks()
|
||||||
|
@ -251,6 +262,11 @@ void PlacesItemModel::loadBookmarks()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PLACESITEMMODEL_DEBUG
|
||||||
|
kDebug() << "Loaded bookmarks";
|
||||||
|
showModelState();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacesItemModel::createSystemBookmarks()
|
void PlacesItemModel::createSystemBookmarks()
|
||||||
|
@ -326,14 +342,17 @@ int PlacesItemModel::hiddenIndex(int index) const
|
||||||
{
|
{
|
||||||
int hiddenIndex = 0;
|
int hiddenIndex = 0;
|
||||||
int visibleItemIndex = 0;
|
int visibleItemIndex = 0;
|
||||||
while (visibleItemIndex < index && hiddenIndex < m_hiddenItems.count()) {
|
while (hiddenIndex < m_hiddenItems.count()) {
|
||||||
if (!m_hiddenItems[hiddenIndex]) {
|
if (!m_hiddenItems[hiddenIndex]) {
|
||||||
|
if (visibleItemIndex == index) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
++visibleItemIndex;
|
++visibleItemIndex;
|
||||||
}
|
}
|
||||||
++hiddenIndex;
|
++hiddenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hiddenIndex;
|
return hiddenIndex >= m_hiddenItems.count() ? -1 : hiddenIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PlacesItemModel::placesGroupName()
|
QString PlacesItemModel::placesGroupName()
|
||||||
|
@ -445,4 +464,20 @@ KUrl PlacesItemModel::searchUrlForTerm(const Nepomuk::Query::Term& term)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PLACESITEMMODEL_DEBUG
|
||||||
|
void PlacesItemModel::showModelState()
|
||||||
|
{
|
||||||
|
kDebug() << "hidden-index model-index text";
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < m_hiddenItems.count(); ++i) {
|
||||||
|
if (m_hiddenItems[i]) {
|
||||||
|
kDebug() << i << "(Hidden) " << " " << m_hiddenItems[i]->dataValue("text").toString();
|
||||||
|
} else {
|
||||||
|
kDebug() << i << " " << j << " " << item(j)->dataValue("text").toString();
|
||||||
|
++j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "placesitemmodel.moc"
|
#include "placesitemmodel.moc"
|
||||||
|
|
|
@ -42,6 +42,14 @@ class QAction;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define PLACESITEMMODEL_DEBUG
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Model for maintaining the bookmarks of the places panel.
|
||||||
|
*
|
||||||
|
* It is compatible to the KFilePlacesModel from kdelibs but adds
|
||||||
|
* the ability to have groups for places.
|
||||||
|
*/
|
||||||
class PlacesItemModel: public KStandardItemModel
|
class PlacesItemModel: public KStandardItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -89,8 +97,17 @@ protected:
|
||||||
private:
|
private:
|
||||||
void loadBookmarks();
|
void loadBookmarks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates system bookmarks that are shown per default and can
|
||||||
|
* only be hidden but not removed. The result will be stored
|
||||||
|
* in m_systemBookmarks.
|
||||||
|
*/
|
||||||
void createSystemBookmarks();
|
void createSystemBookmarks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param index Item index related to the model.
|
||||||
|
* @return Corresponding item index related to m_hiddenItems.
|
||||||
|
*/
|
||||||
int hiddenIndex(int index) const;
|
int hiddenIndex(int index) const;
|
||||||
|
|
||||||
static QString placesGroupName();
|
static QString placesGroupName();
|
||||||
|
@ -127,6 +144,10 @@ private:
|
||||||
static KUrl searchUrlForTerm(const Nepomuk::Query::Term& term);
|
static KUrl searchUrlForTerm(const Nepomuk::Query::Term& term);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PLACESITEMMODEL_DEBUG
|
||||||
|
void showModelState();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_nepomukRunning;
|
bool m_nepomukRunning;
|
||||||
bool m_hiddenItemsShown;
|
bool m_hiddenItemsShown;
|
||||||
|
|
Loading…
Reference in a new issue