Restore compatibility with GCC 7.5.0

This old compiler version (which is still used in the CI) apparently runs
into the following error:
```
CMakeFiles/pianobooster.dir/QtWindow.o: In function `QtWindow::updateRecentFileActions()':
QtWindow.cpp:(.text+0x4bd2): undefined reference to `QtWindow::MAX_RECENT_FILES'
```
Using a function should workaround this problem.
This commit is contained in:
Martchus 2022-12-31 21:52:40 +01:00 committed by Fabien Givors
parent f8d26cf5f8
commit 540294593c
2 changed files with 9 additions and 9 deletions

View File

@ -72,7 +72,7 @@ QtWindow::QtWindow()
ppLogInfo("Open GL Swap Interval %d", value);
}
for (int i = 0; i < MAX_RECENT_FILES; ++i)
for (int i = 0; i < maxRecentFiles(); ++i)
m_recentFileActs[i] = nullptr;
m_separatorAct = nullptr;
@ -400,7 +400,7 @@ void QtWindow::createActions()
addShortcutAction("ShortCuts/NextBook", SLOT(on_nextBook()));
addShortcutAction("ShortCuts/PreviousBook", SLOT(on_previousBook()));
for (int i = 0; i < MAX_RECENT_FILES; ++i) {
for (int i = 0; i < maxRecentFiles(); ++i) {
m_recentFileActs[i] = new QAction(this);
m_recentFileActs[i]->setVisible(false);
connect(m_recentFileActs[i], SIGNAL(triggered()),
@ -414,7 +414,7 @@ void QtWindow::createMenus()
m_fileMenu->setToolTipsVisible(true);
m_fileMenu->addAction(m_openAct);
m_separatorAct = m_fileMenu->addSeparator();
for (int i = 0; i < MAX_RECENT_FILES; ++i)
for (int i = 0; i < maxRecentFiles(); ++i)
m_fileMenu->addAction(m_recentFileActs[i]);
m_fileMenu->addSeparator();
m_fileMenu->addAction(m_exitAct);
@ -479,7 +479,7 @@ void QtWindow::updateRecentFileActions()
QStringList files = m_settings->value("RecentFileList").toStringList();
int numRecentFiles = qMin(files.size(), MAX_RECENT_FILES);
int numRecentFiles = qMin(files.size(), maxRecentFiles());
for (int i = 0; i < numRecentFiles; ++i) {
QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
@ -490,7 +490,7 @@ void QtWindow::updateRecentFileActions()
m_recentFileActs[i]->setVisible(true);
}
for (int j = numRecentFiles; j < MAX_RECENT_FILES; ++j) {
for (int j = numRecentFiles; j < maxRecentFiles(); ++j) {
if (m_recentFileActs[j] == nullptr)
break;
m_recentFileActs[j]->setVisible(false);
@ -514,7 +514,7 @@ void QtWindow::setCurrentFile(const QString &fileName)
QStringList files = m_settings->value("RecentFileList").toStringList();
files.removeAll(fileName);
files.prepend(fileName);
while (files.size() > MAX_RECENT_FILES)
while (files.size() > maxRecentFiles())
files.removeLast();
m_settings->setValue("RecentFileList", files);

View File

@ -48,6 +48,8 @@ class QSlider;
class QPushButton;
class QTextBrowser;
static constexpr int maxRecentFiles() { return 20; }
class QtWindow : public QMainWindow
{
Q_OBJECT
@ -226,9 +228,7 @@ private:
CScore* m_score;
QAction *m_separatorAct;
static constexpr int MAX_RECENT_FILES = 20;
QAction *m_recentFileActs[MAX_RECENT_FILES];
QAction *m_recentFileActs[maxRecentFiles()];
};
#endif // __QT_WINDOW_H__