fix: Fix the issue where no space is reserved after dragging out the …#1486
fix: Fix the issue where no space is reserved after dragging out the …#1486BLumia merged 1 commit intolinuxdeepin:masterfrom
Conversation
Reviewer's GuideImplements a staged drop mechanism and size reset for the tray to ensure space is correctly reserved and previewed when dragging items from the stash to the dock tray, adjusting both model logic and QML drag handling. Sequence diagram for staged tray drop from stash to dock traysequenceDiagram
actor User
participant TrayContainerQML
participant TraySortOrderModel
participant TrayItemPositionManager
User->>TrayContainerQML: drag item from stash over tray
TrayContainerQML->>TrayItemPositionManager: itemIndexByPoint(point)
TrayItemPositionManager-->>TrayContainerQML: index,isBefore
TrayContainerQML->>TraySortOrderModel: stageDropPosition(surfaceId, visualIndex)
TraySortOrderModel->>TraySortOrderModel: set m_stagedSurfaceId,m_stagedVisualIndex
TraySortOrderModel-->>TrayContainerQML: stagedDropChanged
TraySortOrderModel->>TraySortOrderModel: updateVisualIndexes()
TraySortOrderModel->>TrayItemPositionManager: clearRegisteredSizes()
TrayItemPositionManager->>TrayItemPositionManager: m_registeredItemsSize.clear()
TrayItemPositionManager-->>TraySortOrderModel: visualItemSizeChanged
loop assign visual indexes
TraySortOrderModel->>TraySortOrderModel: reserveStagedDropSpace(currentVisualIndex)
TraySortOrderModel->>TraySortOrderModel: skip index when currentVisualIndex == m_stagedVisualIndex
end
User->>TrayContainerQML: drop item in tray
TrayContainerQML->>TrayItemPositionManager: itemIndexByPoint(point)
TrayItemPositionManager-->>TrayContainerQML: index,isBefore
TrayContainerQML->>TraySortOrderModel: commitStagedDrop()
TraySortOrderModel->>TraySortOrderModel: dropToDockTray(m_stagedSurfaceId,m_stagedVisualIndex,true)
TraySortOrderModel->>TraySortOrderModel: clear m_stagedSurfaceId,m_stagedVisualIndex
TraySortOrderModel-->>TrayContainerQML: stagedDropChanged
TraySortOrderModel->>TraySortOrderModel: updateVisualIndexes()
Class diagram for updated tray sort and position managementclassDiagram
class TraySortOrderModel {
// properties
int m_visualItemCount
bool m_collapsed
bool m_actionsAlwaysVisible
bool m_isUpdating
QStringList m_sectionTray
QStringList m_sectionStash
QStringList m_sectionFixed
QStringList m_disabledIds
QStringList m_hiddenIds
QStringList m_dockHiddenIds
QString m_stagedSurfaceId
int m_stagedVisualIndex
// Q_PROPERTIES
bool actionsAlwaysVisible
bool isUpdating
QList~QVariantMap~ availableSurfaces
QString stagedSurfaceId
int stagedVisualIndex
// invokable methods
void dropToDockTray(QString surfaceId, int visualIndex, bool isBefore)
void setDockVisible(QString surfaceId, bool visible)
bool isDockVisible(QString surfaceId) const
QModelIndex getModelIndexByVisualIndex(int visualIndex) const
void stageDropPosition(QString surfaceId, int visualIndex)
void commitStagedDrop()
void clearStagedDrop()
// internal helpers
void updateVisualIndexes()
void reserveStagedDropSpace(int& currentVisualIndex)
QStandardItem* findItemByVisualIndex(int visualIndex, VisualSections visualSection) const
QStringList* getSection(QString sectionType)
QString findSection(QString surfaceId, QString fallback, QStringList forbiddenSections, int pluginFlags)
void registerToSection(QString surfaceId, QString sectionType)
QStandardItem* createTrayItem(QString name, QString surfaceId, QString sectionType)
// signals
void collapsedChanged(bool)
void actionsAlwaysVisibleChanged(bool)
void isUpdatingChanged(bool)
void visualItemCountChanged(int)
void availableSurfacesChanged(QList~QVariantMap~)
void stagedDropChanged()
}
class TrayItemPositionManager {
// properties
QHash~QString,QSize~ m_registeredItemsSize
Qt::Orientation m_orientation
int m_dockHeight
// invokable methods
int itemIndexByPoint(QPoint point)
Qt::Orientation orientation() const
int dockHeight() const
void layoutHealthCheck(int delayMs = 200)
void clearRegisteredSizes()
// signals
void orientationChanged(Qt::Orientation)
void dockHeightChanged(int)
void visualItemSizeChanged()
}
TraySortOrderModel --> TrayItemPositionManager : uses
TraySortOrderModel ..> QStandardItemModel : inherits
TrayItemPositionManager ..> QObject : inherits
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- Calling
TrayItemPositionManager::clearRegisteredSizes()at the start of everyupdateVisualIndexes()(which is now also invoked on every staged drop change) may cause unnecessary relayouts during drag-hover; consider restricting this to cases where the layout actually changes (e.g. only when items are added/removed) or debouncing it for drag previews. - The staged-drop flow currently assumes
isBeforeis alwaystrueincommitStagedDrop; if users can hover between items with a before/after distinction, consider threading theisBeforesemantics through the staging APIs to keep behavior consistent with direct drops.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Calling `TrayItemPositionManager::clearRegisteredSizes()` at the start of every `updateVisualIndexes()` (which is now also invoked on every staged drop change) may cause unnecessary relayouts during drag-hover; consider restricting this to cases where the layout actually changes (e.g. only when items are added/removed) or debouncing it for drag previews.
- The staged-drop flow currently assumes `isBefore` is always `true` in `commitStagedDrop`; if users can hover between items with a before/after distinction, consider threading the `isBefore` semantics through the staging APIs to keep behavior consistent with direct drops.
## Individual Comments
### Comment 1
<location path="panels/dock/tray/traysortordermodel.cpp" line_range="650-658" />
<code_context>
+ emit stagedDropChanged();
+}
+
+void TraySortOrderModel::clearStagedDrop()
+{
+ m_stagedSurfaceId.clear();
+ m_stagedVisualIndex = -1;
+ emit stagedDropChanged();
+
+ // Update visual indexes to remove preview
+ updateVisualIndexes();
+}
+
</code_context>
<issue_to_address>
**suggestion (performance):** Guard clearStagedDrop to avoid redundant stagedDropChanged + updateVisualIndexes when nothing is staged.
Since this can be called when no staged drop is active (e.g. from onExited in QML), we end up emitting stagedDropChanged and running updateVisualIndexes unnecessarily. Consider an early return when m_stagedSurfaceId is empty and m_stagedVisualIndex < 0 to skip redundant work.
```suggestion
void TraySortOrderModel::clearStagedDrop()
{
// Avoid redundant work if there is no staged drop
if (m_stagedSurfaceId.isEmpty() && m_stagedVisualIndex < 0) {
return;
}
m_stagedSurfaceId.clear();
m_stagedVisualIndex = -1;
emit stagedDropChanged();
// Update visual indexes to remove preview
updateVisualIndexes();
}
```
</issue_to_address>
### Comment 2
<location path="panels/dock/tray/trayitempositionmanager.cpp" line_range="122-126" />
<code_context>
qDebug() << "layout health check scheduled!";
}
+void TrayItemPositionManager::clearRegisteredSizes()
+{
+ m_registeredItemsSize.clear();
+ emit visualItemSizeChanged();
+}
+
</code_context>
<issue_to_address>
**suggestion (performance):** Avoid emitting visualItemSizeChanged if registered sizes are already empty.
clearRegisteredSizes always clears m_registeredItemsSize and emits visualItemSizeChanged, even when the map is already empty. Since updateVisualIndexes now calls this unconditionally, that can create many redundant signals. Add a guard (e.g. if (!m_registeredItemsSize.isEmpty())) before clearing and emitting to avoid unnecessary downstream recalculations.
```suggestion
void TrayItemPositionManager::clearRegisteredSizes()
{
if (m_registeredItemsSize.isEmpty()) {
return;
}
m_registeredItemsSize.clear();
emit visualItemSizeChanged();
}
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…tray icon Fix the issue where no space is reserved after dragging out the tray icon Log: Fix the issue where no space is reserved after dragging out the tray icon pms: BUG-288727
deepin pr auto review代码审查报告1. 整体评估这段代码实现了托盘区域(Tray)的拖放功能改进,特别是针对暂存区域(stash area)的拖放操作进行了优化。代码引入了"暂存拖放"(staged drop)机制,允许在拖放过程中预览位置,并在实际放置前预留空间。 2. 语法逻辑分析优点
问题与改进建议TrayContainer.qml
traysortordermodel.cpp
3. 代码质量分析优点
问题与改进建议
4. 代码性能分析问题与改进建议
5. 代码安全分析问题与改进建议
6. 其他建议
总结这段代码实现了托盘区域拖放功能的改进,整体设计合理,但在错误处理、性能优化和状态管理方面还有改进空间。建议在后续版本中逐步完善这些方面,以提高代码的健壮性和性能。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
…tray icon
Fix the issue where no space is reserved after dragging out the tray icon
Log: Fix the issue where no space is reserved after dragging out the tray icon
pms: BUG-288727
Summary by Sourcery
Improve tray icon drag-and-drop behavior by introducing staged drop support and ensuring layout space is correctly reserved during reordering.
New Features:
Bug Fixes:
Enhancements: