forked from qt-creator/qt-creator
Utils: Merge NamesValueModel and EnvironmentModel (1/2)
The abstraction is nowhere used (anymore?)
In order to keep the diff small, this here merges environmentmodel.{h,cpp}
into namevaluemodel.{h,cpp} which will be renamed back to env* in a
second step.
Change-Id: I1e7c14012ec3d3f54d8557f4b737a59ede2283e7
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -44,7 +44,6 @@ add_qtc_library(Utils
|
|||||||
environment.cpp environment.h
|
environment.cpp environment.h
|
||||||
environmentdialog.cpp environmentdialog.h
|
environmentdialog.cpp environmentdialog.h
|
||||||
environmentfwd.h
|
environmentfwd.h
|
||||||
environmentmodel.cpp environmentmodel.h
|
|
||||||
execmenu.cpp execmenu.h
|
execmenu.cpp execmenu.h
|
||||||
expected.h
|
expected.h
|
||||||
externalterminalprocessimpl.cpp externalterminalprocessimpl.h
|
externalterminalprocessimpl.cpp externalterminalprocessimpl.h
|
||||||
|
|||||||
@@ -19,7 +19,4 @@ class PreprocessorMacroDictionary;
|
|||||||
using PreprocessorMacroItem = NameValueItem;
|
using PreprocessorMacroItem = NameValueItem;
|
||||||
using PreprocessorMacroItems = NameValueItems;
|
using PreprocessorMacroItems = NameValueItems;
|
||||||
|
|
||||||
class NameValueModel;
|
|
||||||
class EnvironmentModel;
|
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#include "environmentmodel.h"
|
|
||||||
|
|
||||||
#include "environment.h"
|
|
||||||
|
|
||||||
namespace Utils {
|
|
||||||
|
|
||||||
Environment EnvironmentModel::baseEnvironment() const
|
|
||||||
{
|
|
||||||
return Environment(baseNameValueDictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
void EnvironmentModel::setBaseEnvironment(const Environment &env)
|
|
||||||
{
|
|
||||||
setBaseNameValueDictionary(env.toDictionary());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Utils
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "utils_global.h"
|
|
||||||
|
|
||||||
#include "namevaluemodel.h"
|
|
||||||
|
|
||||||
namespace Utils {
|
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT EnvironmentModel : public NameValueModel
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Environment baseEnvironment() const;
|
|
||||||
void setBaseEnvironment(const Environment &env);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Utils
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "namevaluemodel.h"
|
#include "namevaluemodel.h"
|
||||||
|
|
||||||
#include "algorithm.h"
|
#include "algorithm.h"
|
||||||
|
#include "environment.h"
|
||||||
#include "hostosinfo.h"
|
#include "hostosinfo.h"
|
||||||
#include "namevaluedictionary.h"
|
#include "namevaluedictionary.h"
|
||||||
#include "namevalueitem.h"
|
#include "namevalueitem.h"
|
||||||
@@ -20,7 +21,7 @@ namespace Utils {
|
|||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class NameValueModelPrivate
|
class EnvironmentModelPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void updateResultNameValueDictionary()
|
void updateResultNameValueDictionary()
|
||||||
@@ -78,21 +79,22 @@ public:
|
|||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|
||||||
NameValueModel::NameValueModel(QObject *parent)
|
EnvironmentModel::EnvironmentModel(QObject *parent)
|
||||||
: QAbstractTableModel(parent)
|
: QAbstractTableModel(parent)
|
||||||
, d(std::make_unique<Internal::NameValueModelPrivate>())
|
, d(std::make_unique<Internal::EnvironmentModelPrivate>())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
NameValueModel::~NameValueModel() = default;
|
EnvironmentModel::~EnvironmentModel() = default;
|
||||||
|
|
||||||
QString NameValueModel::indexToVariable(const QModelIndex &index) const
|
QString EnvironmentModel::indexToVariable(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
const auto it = std::next(d->m_resultNameValueDictionary.constBegin(), index.row());
|
const auto it = std::next(d->m_resultNameValueDictionary.constBegin(), index.row());
|
||||||
return d->m_resultNameValueDictionary.key(it);
|
return d->m_resultNameValueDictionary.key(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NameValueModel::setBaseNameValueDictionary(const NameValueDictionary &dictionary)
|
void EnvironmentModel::setBaseEnvironment(const Environment &env)
|
||||||
{
|
{
|
||||||
|
const NameValueDictionary dictionary = env.toDictionary();
|
||||||
if (d->m_baseNameValueDictionary == dictionary)
|
if (d->m_baseNameValueDictionary == dictionary)
|
||||||
return;
|
return;
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
@@ -101,14 +103,14 @@ void NameValueModel::setBaseNameValueDictionary(const NameValueDictionary &dicti
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
int NameValueModel::rowCount(const QModelIndex &parent) const
|
int EnvironmentModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return d->m_resultNameValueDictionary.size();
|
return d->m_resultNameValueDictionary.size();
|
||||||
}
|
}
|
||||||
int NameValueModel::columnCount(const QModelIndex &parent) const
|
int EnvironmentModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
@@ -116,17 +118,17 @@ int NameValueModel::columnCount(const QModelIndex &parent) const
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NameValueModel::changes(const QString &name) const
|
bool EnvironmentModel::changes(const QString &name) const
|
||||||
{
|
{
|
||||||
return d->findInChanges(name) >= 0;
|
return d->findInChanges(name) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NameValueDictionary &NameValueModel::baseNameValueDictionary() const
|
Environment EnvironmentModel::baseEnvironment() const
|
||||||
{
|
{
|
||||||
return d->m_baseNameValueDictionary;
|
return Environment(d->m_baseNameValueDictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant NameValueModel::data(const QModelIndex &index, int role) const
|
QVariant EnvironmentModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -176,13 +178,13 @@ QVariant NameValueModel::data(const QModelIndex &index, int role) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags NameValueModel::flags(const QModelIndex &index) const
|
Qt::ItemFlags EnvironmentModel::flags(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(index)
|
Q_UNUSED(index)
|
||||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant NameValueModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant EnvironmentModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
|
if (orientation == Qt::Vertical || role != Qt::DisplayRole)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -192,7 +194,7 @@ QVariant NameValueModel::headerData(int section, Qt::Orientation orientation, in
|
|||||||
/// *****************
|
/// *****************
|
||||||
/// Utility functions
|
/// Utility functions
|
||||||
/// *****************
|
/// *****************
|
||||||
QModelIndex NameValueModel::variableToIndex(const QString &name) const
|
QModelIndex EnvironmentModel::variableToIndex(const QString &name) const
|
||||||
{
|
{
|
||||||
int row = d->findInResult(name);
|
int row = d->findInResult(name);
|
||||||
if (row == -1)
|
if (row == -1)
|
||||||
@@ -200,7 +202,7 @@ QModelIndex NameValueModel::variableToIndex(const QString &name) const
|
|||||||
return index(row, 0);
|
return index(row, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NameValueModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool EnvironmentModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
if (!index.isValid() || role != Qt::EditRole)
|
if (!index.isValid() || role != Qt::EditRole)
|
||||||
return false;
|
return false;
|
||||||
@@ -262,12 +264,12 @@ bool NameValueModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex NameValueModel::addVariable()
|
QModelIndex EnvironmentModel::addVariable()
|
||||||
{
|
{
|
||||||
return addVariable(NameValueItem("NEWVAR", "VALUE"));
|
return addVariable(NameValueItem("NEWVAR", "VALUE"));
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndex NameValueModel::addVariable(const NameValueItem &item)
|
QModelIndex EnvironmentModel::addVariable(const NameValueItem &item)
|
||||||
{
|
{
|
||||||
// Return existing index if the name is already in the result set:
|
// Return existing index if the name is already in the result set:
|
||||||
int pos = d->findInResult(item.name);
|
int pos = d->findInResult(item.name);
|
||||||
@@ -298,7 +300,7 @@ QModelIndex NameValueModel::addVariable(const NameValueItem &item)
|
|||||||
return index(insertPos, 0, QModelIndex());
|
return index(insertPos, 0, QModelIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NameValueModel::resetVariable(const QString &name)
|
void EnvironmentModel::resetVariable(const QString &name)
|
||||||
{
|
{
|
||||||
int rowInChanges = d->findInChanges(name);
|
int rowInChanges = d->findInChanges(name);
|
||||||
if (rowInChanges < 0)
|
if (rowInChanges < 0)
|
||||||
@@ -323,7 +325,7 @@ void NameValueModel::resetVariable(const QString &name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NameValueModel::unsetVariable(const QString &name)
|
void EnvironmentModel::unsetVariable(const QString &name)
|
||||||
{
|
{
|
||||||
// This does not change the number of rows as we will display a <UNSET>
|
// This does not change the number of rows as we will display a <UNSET>
|
||||||
// in place of the original variable!
|
// in place of the original variable!
|
||||||
@@ -347,7 +349,7 @@ void NameValueModel::unsetVariable(const QString &name)
|
|||||||
emit userChangesChanged();
|
emit userChangesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NameValueModel::toggleVariable(const QModelIndex &idx)
|
void EnvironmentModel::toggleVariable(const QModelIndex &idx)
|
||||||
{
|
{
|
||||||
const QString name = indexToVariable(idx);
|
const QString name = indexToVariable(idx);
|
||||||
const auto newIt = d->m_resultNameValueDictionary.constFind(name);
|
const auto newIt = d->m_resultNameValueDictionary.constFind(name);
|
||||||
@@ -371,28 +373,28 @@ void NameValueModel::toggleVariable(const QModelIndex &idx)
|
|||||||
emit userChangesChanged();
|
emit userChangesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NameValueModel::isUnset(const QString &name)
|
bool EnvironmentModel::isUnset(const QString &name)
|
||||||
{
|
{
|
||||||
const int pos = d->findInChanges(name);
|
const int pos = d->findInChanges(name);
|
||||||
return pos == -1 ? false : d->m_items.at(pos).operation == NameValueItem::Unset;
|
return pos == -1 ? false : d->m_items.at(pos).operation == NameValueItem::Unset;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NameValueModel::isEnabled(const QString &name) const
|
bool EnvironmentModel::isEnabled(const QString &name) const
|
||||||
{
|
{
|
||||||
return d->m_resultNameValueDictionary.isEnabled(d->m_resultNameValueDictionary.constFind(name));
|
return d->m_resultNameValueDictionary.isEnabled(d->m_resultNameValueDictionary.constFind(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NameValueModel::canReset(const QString &name)
|
bool EnvironmentModel::canReset(const QString &name)
|
||||||
{
|
{
|
||||||
return d->m_baseNameValueDictionary.hasKey(name);
|
return d->m_baseNameValueDictionary.hasKey(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
NameValueItems NameValueModel::userChanges() const
|
NameValueItems EnvironmentModel::userChanges() const
|
||||||
{
|
{
|
||||||
return d->m_items;
|
return d->m_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NameValueModel::setUserChanges(const NameValueItems &items)
|
void EnvironmentModel::setUserChanges(const NameValueItems &items)
|
||||||
{
|
{
|
||||||
NameValueItems filtered = Utils::filtered(items, [](const NameValueItem &i) {
|
NameValueItems filtered = Utils::filtered(items, [](const NameValueItem &i) {
|
||||||
return i.name != "export " && !i.name.contains('=');
|
return i.name != "export " && !i.name.contains('=');
|
||||||
@@ -421,7 +423,7 @@ void NameValueModel::setUserChanges(const NameValueItems &items)
|
|||||||
emit userChangesChanged();
|
emit userChangesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NameValueModel::currentEntryIsPathList(const QModelIndex ¤t) const
|
bool EnvironmentModel::currentEntryIsPathList(const QModelIndex ¤t) const
|
||||||
{
|
{
|
||||||
if (!current.isValid())
|
if (!current.isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -13,17 +13,15 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal { class EnvironmentModelPrivate; }
|
||||||
class NameValueModelPrivate;
|
|
||||||
}
|
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT NameValueModel : public QAbstractTableModel
|
class QTCREATOR_UTILS_EXPORT EnvironmentModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NameValueModel(QObject *parent = nullptr);
|
explicit EnvironmentModel(QObject *parent = nullptr);
|
||||||
~NameValueModel() override;
|
~EnvironmentModel() override;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
int columnCount(const QModelIndex &parent) const override;
|
int columnCount(const QModelIndex &parent) const override;
|
||||||
@@ -34,6 +32,9 @@ public:
|
|||||||
Qt::Orientation orientation,
|
Qt::Orientation orientation,
|
||||||
int role = Qt::DisplayRole) const override;
|
int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
|
Environment baseEnvironment() const;
|
||||||
|
void setBaseEnvironment(const Environment &env);
|
||||||
|
|
||||||
QModelIndex addVariable();
|
QModelIndex addVariable();
|
||||||
QModelIndex addVariable(const NameValueItem &item);
|
QModelIndex addVariable(const NameValueItem &item);
|
||||||
void resetVariable(const QString &name);
|
void resetVariable(const QString &name);
|
||||||
@@ -45,8 +46,6 @@ public:
|
|||||||
QString indexToVariable(const QModelIndex &index) const;
|
QString indexToVariable(const QModelIndex &index) const;
|
||||||
QModelIndex variableToIndex(const QString &name) const;
|
QModelIndex variableToIndex(const QString &name) const;
|
||||||
bool changes(const QString &key) const;
|
bool changes(const QString &key) const;
|
||||||
const NameValueDictionary &baseNameValueDictionary() const;
|
|
||||||
void setBaseNameValueDictionary(const NameValueDictionary &dictionary);
|
|
||||||
NameValueItems userChanges() const;
|
NameValueItems userChanges() const;
|
||||||
void setUserChanges(const NameValueItems &items);
|
void setUserChanges(const NameValueItems &items);
|
||||||
bool currentEntryIsPathList(const QModelIndex ¤t) const;
|
bool currentEntryIsPathList(const QModelIndex ¤t) const;
|
||||||
@@ -59,7 +58,7 @@ signals:
|
|||||||
void focusIndex(const QModelIndex &index);
|
void focusIndex(const QModelIndex &index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Internal::NameValueModelPrivate> d;
|
std::unique_ptr<Internal::EnvironmentModelPrivate> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
NameValueValidator::NameValueValidator(QWidget *parent,
|
NameValueValidator::NameValueValidator(QWidget *parent,
|
||||||
NameValueModel *model,
|
EnvironmentModel *model,
|
||||||
QTreeView *view,
|
QTreeView *view,
|
||||||
const QModelIndex &index,
|
const QModelIndex &index,
|
||||||
const QString &toolTipText)
|
const QString &toolTipText)
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class NameValueModel;
|
class EnvironmentModel;
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT NameValueValidator : public QValidator
|
class QTCREATOR_UTILS_EXPORT NameValueValidator : public QValidator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NameValueValidator(QWidget *parent,
|
NameValueValidator(QWidget *parent,
|
||||||
NameValueModel *model,
|
EnvironmentModel *model,
|
||||||
QTreeView *view,
|
QTreeView *view,
|
||||||
const QModelIndex &index,
|
const QModelIndex &index,
|
||||||
const QString &toolTipText);
|
const QString &toolTipText);
|
||||||
@@ -33,7 +33,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_toolTipText;
|
const QString m_toolTipText;
|
||||||
NameValueModel *m_model;
|
EnvironmentModel *m_model;
|
||||||
QTreeView *m_view;
|
QTreeView *m_view;
|
||||||
QPersistentModelIndex m_index;
|
QPersistentModelIndex m_index;
|
||||||
mutable QTimer m_hideTipTimer;
|
mutable QTimer m_hideTipTimer;
|
||||||
|
|||||||
@@ -101,8 +101,6 @@ QtcLibrary {
|
|||||||
"environment.h",
|
"environment.h",
|
||||||
"environmentdialog.cpp",
|
"environmentdialog.cpp",
|
||||||
"environmentdialog.h",
|
"environmentdialog.h",
|
||||||
"environmentmodel.cpp",
|
|
||||||
"environmentmodel.h",
|
|
||||||
"execmenu.cpp",
|
"execmenu.cpp",
|
||||||
"execmenu.h",
|
"execmenu.h",
|
||||||
"externalterminalprocessimpl.cpp",
|
"externalterminalprocessimpl.cpp",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <utils/detailswidget.h>
|
#include <utils/detailswidget.h>
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/environmentdialog.h>
|
#include <utils/environmentdialog.h>
|
||||||
#include <utils/environmentmodel.h>
|
#include <utils/namevaluemodel.h>
|
||||||
#include <utils/headerviewstretcher.h>
|
#include <utils/headerviewstretcher.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/itemviews.h>
|
#include <utils/itemviews.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user