From de1d5f6a949f8335b3dbe000057805a8efdd4487 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 19 Aug 2020 12:41:17 +0200 Subject: QFileSystemModel: don't display a modal messagebox on error A model is the wrong place to display a modal dialog when a call to setData failed. The call returns false already, and the caller can handle the error appropriately, presumably knowing best what failed and how to present the user with options. Task-number: QTBUG-66177 Change-Id: I069209d51a577177bc278aeb08a92c95029dc962 Reviewed-by: Mitch Curtis --- src/widgets/dialogs/qfilesystemmodel.cpp | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'src/widgets/dialogs') diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index f088712987..4b933cdb8d 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtWidgets module of the Qt Toolkit. @@ -43,10 +43,6 @@ #include #include #include -#if QT_CONFIG(messagebox) -#include -#endif -#include #include #if QT_CONFIG(regularexpression) # include @@ -853,20 +849,6 @@ QIcon QFileSystemModelPrivate::icon(const QModelIndex &index) const return node(index)->icon(); } -static void displayRenameFailedMessage(const QString &newName) -{ -#if QT_CONFIG(messagebox) - const QString message = - QFileSystemModel::tr("The name \"%1\" cannot be used." - "

Try using another name, with fewer characters or no punctuation marks.") - .arg(newName); - QMessageBox::information(nullptr, QFileSystemModel::tr("Invalid filename"), - message, QMessageBox::Ok); -#else - Q_UNUSED(newName); -#endif // QT_CONFIG(messagebox) -} - /*! \reimp */ @@ -887,10 +869,8 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in const QString parentPath = filePath(parent(idx)); - if (newName.isEmpty() || QDir::toNativeSeparators(newName).contains(QDir::separator())) { - displayRenameFailedMessage(newName); + if (newName.isEmpty() || QDir::toNativeSeparators(newName).contains(QDir::separator())) return false; - } #if QT_CONFIG(filesystemwatcher) && defined(Q_OS_WIN) // QTBUG-65683: Remove file system watchers prior to renaming to prevent @@ -901,7 +881,6 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in #if QT_CONFIG(filesystemwatcher) && defined(Q_OS_WIN) d->watchPaths(watchedPaths); #endif - displayRenameFailedMessage(newName); return false; } else { /* -- cgit v1.2.3