forked from qt-creator/qt-creator
Qmake: Improve the build dir location warning
The infamous "build dir is not at the same level at source dir" warning
for qmake projects has gone through a number of iterations in Qt
Creator, having been added, removed and re-added, always to the
criticism of some users. Our new approach is as follows:
- The warning appears at the widgets where the build directory is
set, both in the target setup page and the build config widget.
- The warning also appears in the issues pane, but only if the build
failed.
- The user can disable the warning altogether in a newly introduced
qmake settings page.
- This option is disabled by default on Unix, because to my
knowledge all failure reports have been for Windows hosts.
This should finally please everybody.
Fixes: QTCREATORBUG-16945
Change-Id: I638be1f15e8c260a5d72047d6850a3a0f685cf03
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
141
src/plugins/qmakeprojectmanager/qmakesettings.cpp
Normal file
141
src/plugins/qmakeprojectmanager/qmakesettings.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2019 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qmakesettings.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QCoreApplication>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace QmakeProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
const char BUILD_DIR_WARNING_KEY[] = "QmakeProjectManager/WarnAgainstUnalignedBuildDir";
|
||||
|
||||
static bool operator==(const QmakeSettingsData &s1, const QmakeSettingsData &s2)
|
||||
{
|
||||
return s1.warnAgainstUnalignedBuildDir == s2.warnAgainstUnalignedBuildDir;
|
||||
}
|
||||
static bool operator!=(const QmakeSettingsData &s1, const QmakeSettingsData &s2)
|
||||
{
|
||||
return !(s1 == s2);
|
||||
}
|
||||
|
||||
bool QmakeSettings::warnAgainstUnalignedBuildDir()
|
||||
{
|
||||
return instance().m_settings.warnAgainstUnalignedBuildDir;
|
||||
}
|
||||
|
||||
QmakeSettings &QmakeSettings::instance()
|
||||
{
|
||||
static QmakeSettings theSettings;
|
||||
return theSettings;
|
||||
}
|
||||
|
||||
void QmakeSettings::setSettingsData(const QmakeSettingsData &settings)
|
||||
{
|
||||
if (instance().m_settings != settings) {
|
||||
instance().m_settings = settings;
|
||||
instance().storeSettings();
|
||||
emit instance().settingsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QmakeSettings::QmakeSettings()
|
||||
{
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
void QmakeSettings::loadSettings()
|
||||
{
|
||||
m_settings.warnAgainstUnalignedBuildDir = Core::ICore::settings()->value(
|
||||
BUILD_DIR_WARNING_KEY, Utils::HostOsInfo::isWindowsHost()).toBool();
|
||||
}
|
||||
|
||||
void QmakeSettings::storeSettings() const
|
||||
{
|
||||
Core::ICore::settings()->setValue(BUILD_DIR_WARNING_KEY, warnAgainstUnalignedBuildDir());
|
||||
}
|
||||
|
||||
class QmakeSettingsPage::SettingsWidget : public QWidget
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(QmakeProjectManager::Internal::QmakeSettingsPage)
|
||||
public:
|
||||
SettingsWidget()
|
||||
{
|
||||
m_warnAgainstUnalignedBuildDirCheckbox.setText(tr("Warn if a project's source and "
|
||||
"build directories are not at the same level"));
|
||||
m_warnAgainstUnalignedBuildDirCheckbox.setToolTip(tr("Qmake has subtle bugs that "
|
||||
"can trigger if source and build directory are not at the same level."));
|
||||
m_warnAgainstUnalignedBuildDirCheckbox.setChecked(
|
||||
QmakeSettings::warnAgainstUnalignedBuildDir());
|
||||
const auto layout = new QVBoxLayout(this);
|
||||
layout->addWidget(&m_warnAgainstUnalignedBuildDirCheckbox);
|
||||
layout->addStretch(1);
|
||||
}
|
||||
|
||||
void apply()
|
||||
{
|
||||
QmakeSettingsData settings;
|
||||
settings.warnAgainstUnalignedBuildDir = m_warnAgainstUnalignedBuildDirCheckbox.isChecked();
|
||||
QmakeSettings::setSettingsData(settings);
|
||||
}
|
||||
|
||||
private:
|
||||
QCheckBox m_warnAgainstUnalignedBuildDirCheckbox;
|
||||
};
|
||||
|
||||
QmakeSettingsPage::QmakeSettingsPage()
|
||||
{
|
||||
setId("K.QmakeProjectManager.QmakeSettings");
|
||||
setDisplayName(tr("Qmake"));
|
||||
setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
|
||||
}
|
||||
|
||||
QWidget *QmakeSettingsPage::widget()
|
||||
{
|
||||
if (!m_widget)
|
||||
m_widget = new SettingsWidget;
|
||||
return m_widget;
|
||||
|
||||
}
|
||||
|
||||
void QmakeSettingsPage::apply()
|
||||
{
|
||||
if (m_widget)
|
||||
m_widget->apply();
|
||||
}
|
||||
|
||||
void QmakeSettingsPage::finish()
|
||||
{
|
||||
delete m_widget;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmakeProjectManager
|
||||
Reference in New Issue
Block a user