1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-10 00:43:59 +02:00

RecentFileDialog widgets are pointers

This commit is contained in:
Joakim Thorén 2024-11-24 16:57:44 +01:00
parent 5747781dda
commit bdaaa0b584

View File

@ -455,7 +455,8 @@ void MainWindow::on_actionOpenRecent_triggered()
class RecentFileDialog : public QDialog { class RecentFileDialog : public QDialog {
public: public:
RecentFileDialog(const QStringList& recentFiles, QWidget *parent) : QDialog(parent), layout(this) { RecentFileDialog(const QStringList& recentFiles, QWidget *parent)
: QDialog(parent), layout(new QVBoxLayout(this)), listWidget(new QListWidget(this)) {
setWindowTitle(tr("Recently Opened Files")); setWindowTitle(tr("Recently Opened Files"));
setMinimumWidth(600); setMinimumWidth(600);
@ -465,31 +466,31 @@ void MainWindow::on_actionOpenRecent_triggered()
accept(); accept();
}; };
connect(&listWidget, &QListWidget::itemActivated, this, onSelect); connect(listWidget, &QListWidget::itemActivated, this, onSelect);
for (const QString &file : recentFiles) { for (const QString &file : recentFiles) {
QListWidgetItem *item = new QListWidgetItem(file); QListWidgetItem *item = new QListWidgetItem(file);
listWidget.addItem(item); listWidget->addItem(item);
} }
// Select most recent items by default. // Select most recent items by default.
// This enables a "CTRL+R => Enter"-workflow instead of "CTRL+R => 'mouse click on first item'" // This enables a "CTRL+R => Enter"-workflow instead of "CTRL+R => 'mouse click on first item'"
if(listWidget.count() > 0) { if(listWidget->count() > 0) {
listWidget.item(0)->setSelected(true); listWidget->item(0)->setSelected(true);
} }
layout.setSizeConstraint(QLayout::SetMaximumSize); layout->setSizeConstraint(QLayout::SetMaximumSize);
layout.addWidget(&listWidget); layout->addWidget(listWidget);
} }
QString getSelectedFilePath() const { QString getSelectedFilePath() const {
return listWidget.currentItem()->text(); return listWidget->currentItem()->text();
} }
private: private:
QVBoxLayout layout; QVBoxLayout * layout;
QListWidget listWidget; QListWidget * listWidget;
QString selectedFilePath; QString selectedFilePath;
}; };