-
Notifications
You must be signed in to change notification settings - Fork 55
fix: incorrect window state for JLCPCB #1331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,48 +18,63 @@ DockGroupModel::DockGroupModel(QAbstractItemModel *sourceModel, int role, QObjec | |
| , AbstractTaskManagerInterface(this) | ||
| , m_roleForDeduplication(role) | ||
| { | ||
| connect(this, &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent, int first, int last) { | ||
| Q_UNUSED(first) | ||
| Q_UNUSED(last) | ||
| if (!parent.isValid()) | ||
| return; | ||
| Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); | ||
| }); | ||
| connect(this, &QAbstractItemModel::rowsRemoved, this, [this](const QModelIndex &parent, int first, int last) { | ||
| if (!parent.isValid()) | ||
| return; | ||
|
|
||
| // Update m_currentActiveWindow when windows are removed | ||
| int parentRow = parent.row(); | ||
| if (m_currentActiveWindow.contains(parentRow)) { | ||
| int currentActive = m_currentActiveWindow.value(parentRow); | ||
| int windowCount = RoleGroupModel::rowCount(parent); | ||
|
|
||
| // Check if the current active window was removed | ||
| if (currentActive >= first && currentActive <= last) { | ||
| // Current active window was removed, reset to first window | ||
| resetActiveWindow(parentRow); | ||
| } else if (currentActive > last) { | ||
| // Current active window is after the removed range, shift it back | ||
| int removedCount = last - first + 1; | ||
| m_currentActiveWindow[parentRow] = currentActive - removedCount; | ||
| connect( | ||
| this, | ||
| &QAbstractItemModel::rowsInserted, | ||
| this, | ||
| [this](const QModelIndex &parent, int first, int last) { | ||
| Q_UNUSED(first) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Emitting dataChanged for only the first column may miss updates for other columns. If your model has multiple columns, limiting dataChanged to column 0 may cause the UI to miss updates for other columns. Please confirm whether the model is single-column or update the signal to cover all relevant columns. Suggested implementation: int colCount = columnCount(parent);
if (colCount > 0) {
Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), colCount - 1), {TaskManager::WindowsRole});
}
If |
||
| Q_UNUSED(last) | ||
| if (!parent.isValid()) | ||
| return; | ||
| Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); | ||
| }, | ||
| Qt::QueuedConnection); | ||
| connect( | ||
| this, | ||
| &QAbstractItemModel::rowsRemoved, | ||
| this, | ||
| [this](const QModelIndex &parent, int first, int last) { | ||
| if (!parent.isValid()) | ||
| return; | ||
|
|
||
| // Update m_currentActiveWindow when windows are removed | ||
| int parentRow = parent.row(); | ||
| if (m_currentActiveWindow.contains(parentRow)) { | ||
| int currentActive = m_currentActiveWindow.value(parentRow); | ||
| int windowCount = RoleGroupModel::rowCount(parent); | ||
|
|
||
| // Check if the current active window was removed | ||
| if (currentActive >= first && currentActive <= last) { | ||
| // Current active window was removed, reset to first window | ||
| resetActiveWindow(parentRow); | ||
| } else if (currentActive > last) { | ||
| // Current active window is after the removed range, shift it back | ||
| int removedCount = last - first + 1; | ||
| m_currentActiveWindow[parentRow] = currentActive - removedCount; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question (bug_risk): Guard clause may skip legitimate updates for top-level items. This guard prevents updates to top-level items. If updates to these items are required, consider revising this condition. |
||
| // If currentActive < first, no change needed | ||
| } | ||
| // If currentActive < first, no change needed | ||
| } | ||
|
|
||
| Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); | ||
| }); | ||
|
|
||
| connect(this, &QAbstractItemModel::dataChanged, this, [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) { | ||
| Q_UNUSED(bottomRight) | ||
| if (!topLeft.parent().isValid()) | ||
| return; | ||
| auto parentRow = topLeft.parent().row(); | ||
| Q_EMIT dataChanged(index(parentRow, 0), index(parentRow, 0), roles); | ||
|
|
||
| if (roles.contains(TaskManager::ActiveRole)) | ||
| m_currentActiveWindow.insert(parentRow, topLeft.row()); | ||
| }); | ||
| Q_EMIT dataChanged(index(parent.row(), 0), index(parent.row(), 0), {TaskManager::WindowsRole}); | ||
| }, | ||
| Qt::QueuedConnection); | ||
|
|
||
| connect( | ||
| this, | ||
| &QAbstractItemModel::dataChanged, | ||
| this, | ||
| [this](const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList<int> &roles) { | ||
| Q_UNUSED(bottomRight) | ||
| if (!topLeft.parent().isValid()) | ||
| return; | ||
| auto parentRow = topLeft.parent().row(); | ||
| Q_EMIT dataChanged(index(parentRow, 0), index(parentRow, 0), roles); | ||
|
|
||
| if (roles.contains(TaskManager::ActiveRole)) | ||
| m_currentActiveWindow.insert(parentRow, topLeft.row()); | ||
| }, | ||
| Qt::QueuedConnection); | ||
| } | ||
|
|
||
| QVariant DockGroupModel::data(const QModelIndex &index, int role) const | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider introducing a queuedConnect helper to eliminate repetitive connect boilerplate and simplify the constructor.
Here’s one way to collapse the repeated boiler-plate while keeping all behavior intact:
queuedConnect()helper in your.cpp(above your ctor):connect(..., Qt::QueuedConnection)with:This:
, Qt::QueuedConnectionoverload on each call