From b3095b80c81d9f14e02152b93decd57359ac70bb Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 1 Mar 2021 09:33:02 +0100 Subject: [PATCH] Utils: Remove savedaction.{h,cpp} This was only used in the debugger and fakevim, its functionality is provided now by aspects. Change-Id: I8ec7b9d7693aa350bc65b08fca958afc434635a4 Reviewed-by: David Schulz --- src/libs/utils/CMakeLists.txt | 1 - src/libs/utils/savedaction.cpp | 323 --------------------------------- src/libs/utils/savedaction.h | 106 ----------- src/libs/utils/utils-lib.pri | 2 - src/libs/utils/utils.qbs | 2 - 5 files changed, 434 deletions(-) delete mode 100644 src/libs/utils/savedaction.cpp delete mode 100644 src/libs/utils/savedaction.h diff --git a/src/libs/utils/CMakeLists.txt b/src/libs/utils/CMakeLists.txt index c76e367abc7..de4d340ad62 100644 --- a/src/libs/utils/CMakeLists.txt +++ b/src/libs/utils/CMakeLists.txt @@ -128,7 +128,6 @@ add_qtc_library(Utils reloadpromptutils.cpp reloadpromptutils.h removefiledialog.cpp removefiledialog.h removefiledialog.ui runextensions.cpp runextensions.h - savedaction.cpp savedaction.h savefile.cpp savefile.h scopedswap.h set_algorithm.h diff --git a/src/libs/utils/savedaction.cpp b/src/libs/utils/savedaction.cpp deleted file mode 100644 index 062a12b9231..00000000000 --- a/src/libs/utils/savedaction.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 - -#include "pathchooser.h" -#include "pathlisteditor.h" -#include "qtcassert.h" -#include "qtcsettings.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Utils { - -////////////////////////////////////////////////////////////////////////// -// -// SavedAction -// -////////////////////////////////////////////////////////////////////////// - -/*! - \class Utils::SavedAction - - \brief The SavedAction class is a helper class for actions with persistent - state. -*/ - -SavedAction::SavedAction(QObject *parent) -{ - setParent(parent); - connect(&m_action, &QAction::triggered, this, &SavedAction::actionTriggered); -} - - -/*! - Returns the current value of the object. - - \sa setValue() -*/ -QVariant SavedAction::value() const -{ - return m_value; -} - - -/*! - Sets the current value of the object. If the value changed and - \a doemit is true, the \c valueChanged() signal will be emitted. - - \sa value() -*/ -void SavedAction::setValue(const QVariant &value, bool doemit) -{ - if (value == m_value) - return; - m_value = value; - if (m_action.isCheckable()) - m_action.setChecked(m_value.toBool()); - if (doemit) - emit valueChanged(m_value); -} - - -/*! - Returns the default value to be used when the item does not exist yet - in the settings. - - \sa setDefaultValue() -*/ -QVariant SavedAction::defaultValue() const -{ - return m_defaultValue; -} - - -/*! - Sets the default value to be used when the item does not exist yet - in the settings. - - \sa defaultValue() -*/ -void SavedAction::setDefaultValue(const QVariant &value) -{ - m_defaultValue = value; -} - - -QString SavedAction::toString() const -{ - return QLatin1String("value: ") + m_value.toString() - + QLatin1String(" defaultvalue: ") + m_defaultValue.toString() - + QLatin1String(" settingskey: ") + settingsKey(); -} - -/* - Uses \c settingsGroup() and \c settingsKey() to restore the - item from \a settings, - - \sa settingsKey(), settingsGroup(), writeSettings() -*/ -void SavedAction::readSettings(const QSettings *settings) -{ - if (settingsKey().isEmpty()) - return; - QVariant var = settings->value(settingsKey(), m_defaultValue); - // work around old ini files containing @Invalid() entries - if (m_action.isCheckable() && !var.isValid()) - var = false; - setValue(var); -} - -/* - Uses \c settingsGroup() and \c settingsKey() to write the - item to \a settings, - - \sa settingsKey(), settingsGroup(), readSettings() -*/ -void SavedAction::writeSettings(QSettings *settings) -{ - if (settingsKey().isEmpty()) - return; - QtcSettings::setValueWithDefault(settings, settingsKey(), m_value, m_defaultValue); -} - -/* - A \c SavedAction can be connected to a widget, typically a - checkbox, radiobutton, or a lineedit in some configuration dialog. - - The widget will retrieve its contents from the SavedAction's - value, and - depending on the \a ApplyMode - either write - changes back immediately, or when \s SavedAction::apply() - is called explicitly. - - \sa apply(), disconnectWidget() -*/ -void SavedAction::connectWidget(QWidget *widget, ApplyMode applyMode) -{ - QTC_ASSERT(!m_widget, - qDebug() << "ALREADY CONNECTED: " << widget << m_widget << toString(); return); - m_widget = widget; - - if (auto button = qobject_cast(widget)) { - if (!m_dialogText.isEmpty()) - button->setText(m_dialogText); - button->setChecked(m_value.toBool()); - if (applyMode == ImmediateApply) { - connect(button, &QCheckBox::clicked, - this, [this, button] { setValue(button->isChecked()); }); - } - } else if (auto spinBox = qobject_cast(widget)) { - spinBox->setValue(m_value.toInt()); - if (applyMode == ImmediateApply) { - connect(spinBox, QOverload::of(&QSpinBox::valueChanged), - this, [this, spinBox]() { setValue(spinBox->value()); }); - } - } else if (auto lineEdit = qobject_cast(widget)) { - lineEdit->setText(m_value.toString()); - if (applyMode == ImmediateApply) { - connect(lineEdit, &QLineEdit::editingFinished, - this, [this, lineEdit] { setValue(lineEdit->text()); }); - } - - } else if (auto pathChooser = qobject_cast(widget)) { - pathChooser->setPath(m_value.toString()); - if (applyMode == ImmediateApply) { - auto finished = [this, pathChooser] { setValue(pathChooser->path()); }; - connect(pathChooser, &PathChooser::editingFinished, this, finished); - connect(pathChooser, &PathChooser::browsingFinished, this, finished); - } - } else if (auto groupBox = qobject_cast(widget)) { - if (!groupBox->isCheckable()) - qDebug() << "connectWidget to non-checkable group box" << widget << toString(); - groupBox->setChecked(m_value.toBool()); - if (applyMode == ImmediateApply) { - connect(groupBox, &QGroupBox::toggled, - this, [this, groupBox] { setValue(QVariant(groupBox->isChecked())); }); - } - } else if (auto textEdit = qobject_cast(widget)) { - textEdit->setPlainText(m_value.toString()); - if (applyMode == ImmediateApply) { - connect(textEdit, &QTextEdit::textChanged, - this, [this, textEdit] { setValue(textEdit->toPlainText()); }); - } - } else if (auto editor = qobject_cast(widget)) { - editor->setPathList(m_value.toStringList()); - } else { - qDebug() << "Cannot connect widget " << widget << toString(); - } - - // Copy tooltip, but only if there's nothing explcitly set on the widget yet. - if (widget->toolTip().isEmpty()) - widget->setToolTip(m_action.toolTip()); -} - -/* - Disconnects the \c SavedAction from a widget. - - \sa apply(), connectWidget() -*/ -void SavedAction::disconnectWidget() -{ - m_widget = nullptr; -} - -void SavedAction::apply(QSettings *s) -{ - if (auto button = qobject_cast(m_widget)) - setValue(button->isChecked()); - else if (auto lineEdit = qobject_cast(m_widget)) - setValue(lineEdit->text()); - else if (auto spinBox = qobject_cast(m_widget)) - setValue(spinBox->value()); - else if (auto pathChooser = qobject_cast(m_widget)) - setValue(pathChooser->path()); - else if (auto groupBox = qobject_cast(m_widget)) - setValue(groupBox->isChecked()); - else if (auto textEdit = qobject_cast(m_widget)) - setValue(textEdit->toPlainText()); - else if (auto editor = qobject_cast(m_widget)) - setValue(editor->pathList()); - if (s) - writeSettings(s); -} - -/* - Default text to be used in labels if this SavedAction is - used in a settings dialog. - - This typically is similar to the text this SavedAction shows - when used in menus, but differs in capitalization. - - - \sa text() -*/ -QString SavedAction::dialogText() const -{ - return m_dialogText; -} - -void SavedAction::setDialogText(const QString &dialogText) -{ - m_dialogText = dialogText; -} - -void SavedAction::actionTriggered(bool) -{ - if (m_action.isCheckable()) - setValue(m_action.isChecked()); - if (m_action.actionGroup() && m_action.actionGroup()->isExclusive()) { - // FIXME: should be taken care of more directly - const QList actions = m_action.actionGroup()->actions(); - for (QAction *act : actions) - if (auto dact = qobject_cast(act)) - dact->setValue(bool(act == &m_action)); - } -} - -QAction *SavedAction::action() -{ - return &m_action; -} - -void SavedAction::trigger(const QVariant &data) -{ - m_action.setData(data); - m_action.trigger(); -} - -////////////////////////////////////////////////////////////////////////// -// -// SavedActionSet -// -////////////////////////////////////////////////////////////////////////// - -void SavedActionSet::insert(SavedAction *action, QWidget *widget) -{ - m_list.append(action); - if (widget) - action->connectWidget(widget); -} - -void SavedActionSet::apply(QSettings *settings) -{ - for (SavedAction *action : qAsConst(m_list)) - action->apply(settings); -} - -void SavedActionSet::finish() -{ - for (SavedAction *action : qAsConst(m_list)) - action->disconnectWidget(); -} - -} // namespace Utils diff --git a/src/libs/utils/savedaction.h b/src/libs/utils/savedaction.h deleted file mode 100644 index a6188ab5091..00000000000 --- a/src/libs/utils/savedaction.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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. -** -****************************************************************************/ - -#pragma once - -#include "utils_global.h" - -#include "aspects.h" - -#include - -QT_BEGIN_NAMESPACE -class QSettings; -QT_END_NAMESPACE - -namespace Utils { - -enum ApplyMode { ImmediateApply, DeferedApply }; - -class QTCREATOR_UTILS_EXPORT SavedAction : public BaseAspect -{ - Q_OBJECT - -public: - SavedAction(QObject *parent = nullptr); - - QVariant value() const; - void setValue(const QVariant &value, bool doemit = true); - - QVariant defaultValue() const; - void setDefaultValue(const QVariant &value); - - void trigger(const QVariant &data); - - virtual void readSettings(const QSettings *settings); - virtual void writeSettings(QSettings *settings); - - void connectWidget(QWidget *widget, ApplyMode applyMode = DeferedApply); - void disconnectWidget(); - void apply(QSettings *settings); - - QString toString() const; - - QString dialogText() const; - void setDialogText(const QString &dialogText); - - QAction *action(); - - void setText(const QString &text) { m_action.setText(text); } - void setToolTip(const QString &toolTip) { m_action.setToolTip(toolTip); } - void setCheckable(bool checkable) { m_action.setCheckable(checkable); } - void setChecked(bool checked) { m_action.setChecked(checked); } - void setEnabled(bool enabled) { m_action.setEnabled(enabled); } - void setIcon(const QIcon &icon) { m_action.setIcon(icon); } - -signals: - void valueChanged(const QVariant &newValue); - -private: - void actionTriggered(bool); - - QVariant m_value; - QVariant m_defaultValue; - QString m_dialogText; - QWidget *m_widget = nullptr; - QAction m_action; -}; - -class QTCREATOR_UTILS_EXPORT SavedActionSet -{ -public: - SavedActionSet() = default; - ~SavedActionSet() = default; - - void insert(SavedAction *action, QWidget *widget); - void apply(QSettings *settings); - void finish(); - void clear() { m_list.clear(); } - -private: - QList m_list; -}; - -} // namespace Utils diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index cd9edbbbdb7..fb829bde6cc 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -60,7 +60,6 @@ SOURCES += \ $$PWD/classnamevalidatinglineedit.cpp \ $$PWD/fancylineedit.cpp \ $$PWD/qtcolorbutton.cpp \ - $$PWD/savedaction.cpp \ $$PWD/synchronousprocess.cpp \ $$PWD/savefile.cpp \ $$PWD/fileutils.cpp \ @@ -188,7 +187,6 @@ HEADERS += \ $$PWD/classnamevalidatinglineedit.h \ $$PWD/fancylineedit.h \ $$PWD/qtcolorbutton.h \ - $$PWD/savedaction.h \ $$PWD/consoleprocess.h \ $$PWD/synchronousprocess.h \ $$PWD/savefile.h \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 7c2ff56e065..faeda9174c7 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -232,8 +232,6 @@ Project { "removefiledialog.ui", "runextensions.cpp", "runextensions.h", - "savedaction.cpp", - "savedaction.h", "savefile.cpp", "savefile.h", "scopedswap.h",