bugfix: using an invalid pointer cause crash when inser the item

Change-Id: Ie3f4b284fd3b110b00cba9837b6be17a118cd057
This commit is contained in:
杨万青 2015-10-14 11:17:23 +08:00
parent 2d3f870395
commit a009b4ef63
Notes: Deepin Code Review 2016-06-14 07:19:47 +00:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: <yangwanqing@linuxdeepin.com>
Submitted-by: <yangwanqing@linuxdeepin.com>
Submitted-at: Wed, 14 Oct 2015 14:05:28 +0800
Reviewed-on: https://cr.deepin.io/7749
Project: dde/dde-dock
Branch: refs/heads/master

View File

@ -23,37 +23,39 @@ void DockLayout::addItem(AbstractDockItem *item)
void DockLayout::insertItem(AbstractDockItem *item, int index)
{
if (!item)
QPointer<AbstractDockItem> pItem = item;
if (pItem.isNull())
return;
item->setParent(this);
item->show();
pItem->setParent(this);
pItem->show();
int appCount = m_appList.count();
index = index > appCount ? appCount : (index < 0 ? 0 : index);
m_appList.insert(index,item);
m_appList.insert(index,pItem);
connect(item, &AbstractDockItem::frameUpdate, this, &DockLayout::frameUpdate);
connect(item, &AbstractDockItem::posChanged, this, &DockLayout::frameUpdate);
connect(item, &AbstractDockItem::mouseRelease, this, &DockLayout::slotItemRelease);
connect(item, &AbstractDockItem::dragStart, this, &DockLayout::slotItemDrag);
connect(item, &AbstractDockItem::dragEntered, this, &DockLayout::slotItemEntered);
connect(item, &AbstractDockItem::dragExited, this, &DockLayout::slotItemExited);
connect(item, &AbstractDockItem::widthChanged, this, &DockLayout::relayout);
connect(item, &AbstractDockItem::moveAnimationFinished,this, &DockLayout::slotAnimationFinish);
connect(this, &DockLayout::itemHoverableChange, item, &AbstractDockItem::setHoverable);
connect(pItem, &AbstractDockItem::frameUpdate, this, &DockLayout::frameUpdate);
connect(pItem, &AbstractDockItem::posChanged, this, &DockLayout::frameUpdate);
connect(pItem, &AbstractDockItem::mouseRelease, this, &DockLayout::slotItemRelease);
connect(pItem, &AbstractDockItem::dragStart, this, &DockLayout::slotItemDrag);
connect(pItem, &AbstractDockItem::dragEntered, this, &DockLayout::slotItemEntered);
connect(pItem, &AbstractDockItem::dragExited, this, &DockLayout::slotItemExited);
connect(pItem, &AbstractDockItem::widthChanged, this, &DockLayout::relayout);
connect(pItem, &AbstractDockItem::moveAnimationFinished,this, &DockLayout::slotAnimationFinish);
connect(this, &DockLayout::itemHoverableChange, pItem, &AbstractDockItem::setHoverable);
m_ddam->Sort(itemsIdList());
//hide for delay show
item->setVisible(false);
pItem->setVisible(false);
//Qt5.3.* not support singleshot with lamda expressions
QTimer *delayTimer = new QTimer(this);
connect(delayTimer, &QTimer::timeout, [=] {
delayTimer->stop();
delayTimer->deleteLater();
item->setVisible(true);
if (!pItem.isNull())
item->setVisible(true);
});
delayTimer->start(m_addItemDelayInterval);