From 7eb1696a32891ce4f1f0e44c590a7fdb7c55fecd Mon Sep 17 00:00:00 2001 From: Tem PQD Date: Sun, 21 Sep 2025 20:48:22 +0000 Subject: placespanel: Fix default width by moving things from showEvent to constructor Move instantiation, setModel, and some connections to constructor and remove showEvent. This was being done in an erroneous lazy order which led to the places panel's sizeHint not being called properly. Also removes the double loading workaround in setUrl, which is no longer needed either. BUG: 449070 --- src/panels/places/placespanel.cpp | 43 +++++++++++++++------------------------ src/panels/places/placespanel.h | 2 -- 2 files changed, 16 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index cb3f3183b..12d7619b8 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -67,15 +67,28 @@ PlacesPanel::PlacesPanel(QWidget *parent) settings->setIconSize(iconSize); settings->save(); }); + + readSettings(); + + // Set the model here so that it's loaded in time for the sizeHint to properly apply (setting it upon showEvent is too late) + auto *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); + setModel(placesModel); + + connect(placesModel, &KFilePlacesModel::errorMessage, this, &PlacesPanel::errorMessage); + connect(placesModel, &KFilePlacesModel::teardownDone, this, &PlacesPanel::slotTearDownDone); + + connect(placesModel, &QAbstractItemModel::rowsInserted, this, &PlacesPanel::slotRowsInserted); + connect(placesModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &PlacesPanel::slotRowsAboutToBeRemoved); + + for (int i = 0; i < model()->rowCount(); ++i) { + connectDeviceSignals(model()->index(i, 0, QModelIndex())); + } } PlacesPanel::~PlacesPanel() = default; void PlacesPanel::setUrl(const QUrl &url) { - // KFilePlacesView::setUrl no-ops when no model is set but we only set it in showEvent() - // Remember the URL and set it in showEvent - m_url = url; KFilePlacesView::setUrl(url); } @@ -111,30 +124,6 @@ void PlacesPanel::readSettings() setIconSize(QSize(iconSize, iconSize)); } -void PlacesPanel::showEvent(QShowEvent *event) -{ - if (!event->spontaneous() && !model()) { - readSettings(); - - auto *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); - setModel(placesModel); - - connect(placesModel, &KFilePlacesModel::errorMessage, this, &PlacesPanel::errorMessage); - connect(placesModel, &KFilePlacesModel::teardownDone, this, &PlacesPanel::slotTearDownDone); - - connect(placesModel, &QAbstractItemModel::rowsInserted, this, &PlacesPanel::slotRowsInserted); - connect(placesModel, &QAbstractItemModel::rowsAboutToBeRemoved, this, &PlacesPanel::slotRowsAboutToBeRemoved); - - for (int i = 0; i < model()->rowCount(); ++i) { - connectDeviceSignals(model()->index(i, 0, QModelIndex())); - } - - setUrl(m_url); - } - - KFilePlacesView::showEvent(event); -} - static bool isInternalDrag(const QMimeData *mimeData) { const auto formats = mimeData->formats(); diff --git a/src/panels/places/placespanel.h b/src/panels/places/placespanel.h index cbd5fc224..dd5cb6d9e 100644 --- a/src/panels/places/placespanel.h +++ b/src/panels/places/placespanel.h @@ -54,7 +54,6 @@ Q_SIGNALS: void openInSplitViewRequested(const QUrl &url); protected: - void showEvent(QShowEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; private Q_SLOTS: @@ -70,7 +69,6 @@ private Q_SLOTS: private: void connectDeviceSignals(const QModelIndex &idx); - QUrl m_url; // only used for initial setUrl QList m_customContextMenuActions; QPersistentModelIndex m_indexToTearDown; -- cgit v1.3