diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-06-08 11:51:32 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2018-06-11 07:31:09 +0000 |
commit | 8830cdef9149ebbdd89119a7a9c38ea0b57be986 (patch) | |
tree | 0c08795f7207d507d32a987ee0724127744a2af6 | |
parent | 213c431bce993ec48adee59cd9cbc93b580efda1 (diff) |
Remove non-existent items from recent files list
Avoids crash when trying to load such a presentation.
Task-number: QT3DS-1903
Change-Id: Ic0fdd00243aed2656df248901ebbc444d829dcdd
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Marianne Yrjänä <marianne.yrjana@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/Authoring/Studio/UI/RecentItems.cpp | 36 | ||||
-rw-r--r-- | src/Authoring/Studio/UI/RecentItems.h | 1 |
2 files changed, 20 insertions, 17 deletions
diff --git a/src/Authoring/Studio/UI/RecentItems.cpp b/src/Authoring/Studio/UI/RecentItems.cpp index e7497d40..e2e39c6f 100644 --- a/src/Authoring/Studio/UI/RecentItems.cpp +++ b/src/Authoring/Studio/UI/RecentItems.cpp @@ -32,10 +32,7 @@ #include "RecentItems.h" #include "Preferences.h" -#include <QMenu> - -// using namespace Q3DStudio; <-- Do not do this here because it will conflict with CList and make -// the template generator go blah +#include <QtWidgets/qmenu.h> const Q3DStudio::CString CRecentItems::RECENTITEM_KEY = "RecentItem"; const Q3DStudio::CString CRecentItems::RECENTIMPORT_KEY = "RecentImport"; @@ -49,6 +46,8 @@ CRecentItems::CRecentItems(QMenu *inMenuID, long inCommandID, Q3DStudio::CString m_ValidItems = 10; m_PreferenceKey = inPreferenceKey; + connect(m_Menu, &QMenu::aboutToShow, this, &CRecentItems::handleAboutToShow); + ReconstructList(); } @@ -97,11 +96,8 @@ void CRecentItems::ReconstructList() Q3DStudio::CString theFilename = thePrefs.GetStringValue(theKey, ""); if (theFilename != "") { Qt3DSFile theFile(theFilename); - - QAction *act = m_Menu->addAction(theFile.GetName().toQString(), - this, &CRecentItems::onTriggerRecent); - act->setData(static_cast<int>(m_RecentItems.size())); - m_RecentItems.push_back(theFile); + if (theFile.Exists()) + m_RecentItems.push_back(theFile); } } } @@ -114,19 +110,25 @@ void CRecentItems::RebuildList() thePrefs.SetLongValue(RECENTITEM_VALID, GetItemCount()); TFileList::iterator thePos = m_RecentItems.begin(); for (long theIndex = 0; thePos != m_RecentItems.end(); ++thePos, ++theIndex) { - Q3DStudio::CString theFilename = (*thePos).GetName(); + Qt3DSFile theFile = *thePos; + if (theFile.Exists()) { + QAction *act = m_Menu->addAction(theFile.GetName().toQString(), + this, &CRecentItems::onTriggerRecent); + act->setData(static_cast<int>(theIndex)); - QAction *act = m_Menu->addAction(theFilename.toQString(), - this, &CRecentItems::onTriggerRecent); - act->setData(static_cast<int>(theIndex)); + Q3DStudio::CString theKey; + theKey.Format(_LSTR("%ls%d"), static_cast<const wchar_t *>(m_PreferenceKey), theIndex); - Q3DStudio::CString theKey; - theKey.Format(_LSTR("%ls%d"), static_cast<const wchar_t *>(m_PreferenceKey), theIndex); - - thePrefs.SetStringValue(theKey, (*thePos).GetAbsolutePath()); + thePrefs.SetStringValue(theKey, (*thePos).GetAbsolutePath()); + } } } +void CRecentItems::handleAboutToShow() +{ + RebuildList(); +} + void CRecentItems::ClearMenu() { m_Menu->clear(); diff --git a/src/Authoring/Studio/UI/RecentItems.h b/src/Authoring/Studio/UI/RecentItems.h index 4173646f..db4d62f5 100644 --- a/src/Authoring/Studio/UI/RecentItems.h +++ b/src/Authoring/Studio/UI/RecentItems.h @@ -72,6 +72,7 @@ protected: void ReconstructList(); void RebuildList(); void SaveRecentList(); + void handleAboutToShow(); TFileList m_RecentItems; |