GuiLyXFiles: Fix crash and disabling with header selection

Fixes #11929
This commit is contained in:
Juergen Spitzmueller 2020-08-11 19:26:23 +02:00
parent bafd74c46e
commit 075d220d6e
2 changed files with 24 additions and 9 deletions

View File

@ -210,9 +210,9 @@ GuiLyXFiles::GuiLyXFiles(GuiView & lv)
this, SLOT(slotButtonBox(QAbstractButton *))); this, SLOT(slotButtonBox(QAbstractButton *)));
connect(filesLW, SIGNAL(itemClicked(QTreeWidgetItem *, int)), connect(filesLW, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
this, SLOT(changed_adaptor())); this, SLOT(fileSelectionChanged()));
connect(filesLW, SIGNAL(itemSelectionChanged()), connect(filesLW, SIGNAL(itemSelectionChanged()),
this, SLOT(changed_adaptor())); this, SLOT(fileSelectionChanged()));
connect(filter_, SIGNAL(textEdited(QString)), connect(filter_, SIGNAL(textEdited(QString)),
this, SLOT(filterLabels())); this, SLOT(filterLabels()));
connect(filter_, SIGNAL(rightButtonClicked()), 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(); changed();
} }
@ -277,9 +283,11 @@ void GuiLyXFiles::on_languageCO_activated(int i)
void GuiLyXFiles::on_filesLW_itemDoubleClicked(QTreeWidgetItem * item, int) 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) // not a file (probably a header)
bc().setValid(false);
return; return;
}
applyView(); applyView();
dispatchParams(); dispatchParams();
@ -288,10 +296,17 @@ void GuiLyXFiles::on_filesLW_itemDoubleClicked(QTreeWidgetItem * item, int)
void GuiLyXFiles::on_filesLW_itemClicked(QTreeWidgetItem * item, int) void GuiLyXFiles::on_filesLW_itemClicked(QTreeWidgetItem * item, int)
{ {
QString const data = item->data(0, Qt::UserRole).toString(); if (!item) {
if (!data.endsWith(getSuffix())) bc().setValid(false);
// not a file (probably a header)
return; return;
}
QString const data = item->data(0, Qt::UserRole).toString();
if (!data.endsWith(getSuffix())) {
// not a file (probably a header)
bc().setValid(false);
return;
}
languageCO->clear(); languageCO->clear();
QMap<QString, QString>::const_iterator i =available_languages_.constBegin(); QMap<QString, QString>::const_iterator i =available_languages_.constBegin();
@ -512,7 +527,7 @@ void GuiLyXFiles::resetFilter()
QString const GuiLyXFiles::getRealPath(QString relpath) QString const GuiLyXFiles::getRealPath(QString relpath)
{ {
if (relpath.isEmpty()) if (relpath.isEmpty() && filesLW->currentItem() != nullptr)
relpath = filesLW->currentItem()->data(0, Qt::UserRole).toString(); relpath = filesLW->currentItem()->data(0, Qt::UserRole).toString();
QString const language = languageCO->itemData(languageCO->currentIndex()).toString(); QString const language = languageCO->itemData(languageCO->currentIndex()).toString();
if (localizations_.contains(relpath)) { if (localizations_.contains(relpath)) {

View File

@ -40,7 +40,7 @@ Q_SIGNALS:
void fileSelected(QString const file); void fileSelected(QString const file);
private Q_SLOTS: private Q_SLOTS:
void changed_adaptor(); void fileSelectionChanged();
void on_fileTypeCO_activated(int); void on_fileTypeCO_activated(int);
void on_languageCO_activated(int); void on_languageCO_activated(int);
void on_filesLW_itemDoubleClicked(QTreeWidgetItem *, int); void on_filesLW_itemDoubleClicked(QTreeWidgetItem *, int);