sort plugins when displayMode chanegd

Change-Id: I771a02db3cb52026fe80ab10c2c7a4b0d07f45f8
This commit is contained in:
石博文 2018-03-07 18:05:40 +08:00
parent 7e94385a21
commit 0d2c94fe11
Notes: gerrit 2018-03-07 10:11:20 +00:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Wed, 07 Mar 2018 10:11:19 +0000
Reviewed-on: https://cr.deepin.io/32346
Project: dde/dde-dock
Branch: refs/heads/master
3 changed files with 38 additions and 0 deletions

View File

@ -348,3 +348,38 @@ void DockItemController::reloadAppItems()
for (auto path : m_appInter->entries())
appItemAdded(path, -1);
}
void DockItemController::sortPluginItems()
{
int firstPluginIndex = -1;
for (int i(0); i != m_itemList.size(); ++i)
{
if (m_itemList[i]->itemType() == DockItem::Plugins)
{
firstPluginIndex = i;
break;
}
}
if (firstPluginIndex == -1)
return;
std::sort(m_itemList.begin() + firstPluginIndex, m_itemList.end(), [](DockItem *a, DockItem *b) -> bool {
PluginsItem *pa = static_cast<PluginsItem *>(a);
PluginsItem *pb = static_cast<PluginsItem *>(b);
const int aKey = pa->itemSortKey();
const int bKey = pb->itemSortKey();
if (bKey == -1)
return true;
if (aKey == -1)
return false;
return aKey < bKey;
});
// reset order
for (int i(firstPluginIndex); i != m_itemList.size(); ++i)
emit itemMoved(m_itemList[i], i);
}

View File

@ -55,6 +55,7 @@ signals:
public slots:
void refershItemsIcon();
void sortPluginItems();
void updatePluginsItemOrderKey();
void itemMove(DockItem * const moveItem, DockItem * const replaceItem);
void itemDroppedIntoContainer(DockItem * const item);

View File

@ -356,6 +356,8 @@ void DockSettings::onDisplayModeChanged()
calculateWindowConfig();
emit displayModeChanegd();
QTimer::singleShot(1, m_itemController, &DockItemController::sortPluginItems);
}
void DockSettings::hideModeChanged()