2014-01-09 14:44:25 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-01-09 14:44:25 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2014-01-09 14:44:25 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2014-01-09 14:44:25 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "marginsettings.h"
|
|
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
|
|
static const char showWrapColumnKey[] = "ShowMargin";
|
|
|
|
|
static const char wrapColumnKey[] = "MarginColumn";
|
|
|
|
|
static const char groupPostfix[] = "MarginSettings";
|
2021-01-24 17:11:02 +01:00
|
|
|
static const char useIndenterColumnKey[] = "UseIndenter";
|
2014-01-09 14:44:25 +01:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
|
|
|
|
|
MarginSettings::MarginSettings()
|
|
|
|
|
: m_showMargin(false)
|
2021-01-24 17:11:02 +01:00
|
|
|
, m_useIndenter(false)
|
2014-01-09 14:44:25 +01:00
|
|
|
, m_marginColumn(80)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MarginSettings::toSettings(const QString &category, QSettings *s) const
|
|
|
|
|
{
|
|
|
|
|
QString group = QLatin1String(groupPostfix);
|
|
|
|
|
if (!category.isEmpty())
|
|
|
|
|
group.insert(0, category);
|
|
|
|
|
s->beginGroup(group);
|
|
|
|
|
s->setValue(QLatin1String(showWrapColumnKey), m_showMargin);
|
2021-01-24 17:11:02 +01:00
|
|
|
s->setValue(QLatin1String(useIndenterColumnKey), m_useIndenter);
|
2014-01-09 14:44:25 +01:00
|
|
|
s->setValue(QLatin1String(wrapColumnKey), m_marginColumn);
|
|
|
|
|
s->endGroup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MarginSettings::fromSettings(const QString &category, const QSettings *s)
|
|
|
|
|
{
|
|
|
|
|
QString group = QLatin1String(groupPostfix);
|
|
|
|
|
if (!category.isEmpty())
|
|
|
|
|
group.insert(0, category);
|
|
|
|
|
group += QLatin1Char('/');
|
|
|
|
|
|
|
|
|
|
*this = MarginSettings(); // Assign defaults
|
|
|
|
|
|
|
|
|
|
m_showMargin = s->value(group + QLatin1String(showWrapColumnKey), m_showMargin).toBool();
|
2021-01-24 17:11:02 +01:00
|
|
|
m_useIndenter = s->value(group + QLatin1String(useIndenterColumnKey), m_useIndenter).toBool();
|
2014-01-09 14:44:25 +01:00
|
|
|
m_marginColumn = s->value(group + QLatin1String(wrapColumnKey), m_marginColumn).toInt();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 15:41:12 +02:00
|
|
|
QVariantMap MarginSettings::toMap() const
|
2014-01-09 14:44:25 +01:00
|
|
|
{
|
2021-12-01 15:41:12 +02:00
|
|
|
return {
|
|
|
|
|
{showWrapColumnKey, m_showMargin},
|
|
|
|
|
{useIndenterColumnKey, m_useIndenter},
|
|
|
|
|
{wrapColumnKey, m_marginColumn}
|
|
|
|
|
};
|
2014-01-09 14:44:25 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-01 15:41:12 +02:00
|
|
|
void MarginSettings::fromMap(const QVariantMap &map)
|
2014-01-09 14:44:25 +01:00
|
|
|
{
|
2021-12-01 15:41:12 +02:00
|
|
|
m_showMargin = map.value(showWrapColumnKey, m_showMargin).toBool();
|
|
|
|
|
m_useIndenter = map.value(useIndenterColumnKey, m_useIndenter).toBool();
|
|
|
|
|
m_marginColumn = map.value(wrapColumnKey, m_marginColumn).toInt();
|
2014-01-09 14:44:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MarginSettings::equals(const MarginSettings &other) const
|
|
|
|
|
{
|
|
|
|
|
return m_showMargin == other.m_showMargin
|
2021-01-24 17:11:02 +01:00
|
|
|
&& m_useIndenter == other.m_useIndenter
|
2014-01-09 14:44:25 +01:00
|
|
|
&& m_marginColumn == other.m_marginColumn
|
|
|
|
|
;
|
|
|
|
|
}
|