From 075d220d6e927458c3e38d50fbecd6a7f30ece99 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 11 Aug 2020 19:26:23 +0200 Subject: [PATCH] GuiLyXFiles: Fix crash and disabling with header selection Fixes #11929 --- src/frontends/qt/GuiLyXFiles.cpp | 27 +++++++++++++++++++++------ src/frontends/qt/GuiLyXFiles.h | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/frontends/qt/GuiLyXFiles.cpp b/src/frontends/qt/GuiLyXFiles.cpp index 25b6fa4f67..c9dbf907b4 100644 --- a/src/frontends/qt/GuiLyXFiles.cpp +++ b/src/frontends/qt/GuiLyXFiles.cpp @@ -210,9 +210,9 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv) this, SLOT(slotButtonBox(QAbstractButton *))); connect(filesLW, SIGNAL(itemClicked(QTreeWidgetItem *, int)), - this, SLOT(changed_adaptor())); + this, SLOT(fileSelectionChanged())); connect(filesLW, SIGNAL(itemSelectionChanged()), - this, SLOT(changed_adaptor())); + this, SLOT(fileSelectionChanged())); connect(filter_, SIGNAL(textEdited(QString)), this, SLOT(filterLabels())); connect(filter_, SIGNAL(rightButtonClicked()), @@ -252,8 +252,14 @@ bool GuiLyXFiles::translateName() const } -void GuiLyXFiles::changed_adaptor() +void GuiLyXFiles::fileSelectionChanged() { + if (!filesLW->currentItem() + || !filesLW->currentItem()->data(0, Qt::UserRole).toString().endsWith(getSuffix())) { + // not a file (probably a header) + bc().setValid(false); + return; + } changed(); } @@ -277,9 +283,11 @@ void GuiLyXFiles::on_languageCO_activated(int i) void GuiLyXFiles::on_filesLW_itemDoubleClicked(QTreeWidgetItem * item, int) { - if (!item->data(0, Qt::UserRole).toString().endsWith(getSuffix())) + if (!item || !item->data(0, Qt::UserRole).toString().endsWith(getSuffix())) { // not a file (probably a header) + bc().setValid(false); return; + } applyView(); dispatchParams(); @@ -288,10 +296,17 @@ void GuiLyXFiles::on_filesLW_itemDoubleClicked(QTreeWidgetItem * item, int) void GuiLyXFiles::on_filesLW_itemClicked(QTreeWidgetItem * item, int) { + if (!item) { + bc().setValid(false); + return; + } + QString const data = item->data(0, Qt::UserRole).toString(); - if (!data.endsWith(getSuffix())) + if (!data.endsWith(getSuffix())) { // not a file (probably a header) + bc().setValid(false); return; + } languageCO->clear(); QMap::const_iterator i =available_languages_.constBegin(); @@ -512,7 +527,7 @@ void GuiLyXFiles::resetFilter() QString const GuiLyXFiles::getRealPath(QString relpath) { - if (relpath.isEmpty()) + if (relpath.isEmpty() && filesLW->currentItem() != nullptr) relpath = filesLW->currentItem()->data(0, Qt::UserRole).toString(); QString const language = languageCO->itemData(languageCO->currentIndex()).toString(); if (localizations_.contains(relpath)) { diff --git a/src/frontends/qt/GuiLyXFiles.h b/src/frontends/qt/GuiLyXFiles.h index bc129139a7..62be392ff9 100644 --- a/src/frontends/qt/GuiLyXFiles.h +++ b/src/frontends/qt/GuiLyXFiles.h @@ -40,7 +40,7 @@ Q_SIGNALS: void fileSelected(QString const file); private Q_SLOTS: - void changed_adaptor(); + void fileSelectionChanged(); void on_fileTypeCO_activated(int); void on_languageCO_activated(int); void on_filesLW_itemDoubleClicked(QTreeWidgetItem *, int); -- 2.39.5