2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2016-01-27 10:22:07 +01:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
#include "cmakeconfigitem.h"
|
|
|
|
|
|
2017-09-05 13:55:08 +02:00
|
|
|
#include <utils/treemodel.h>
|
2016-01-27 10:22:07 +01:00
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
namespace CMakeProjectManager::Internal {
|
2016-01-27 10:22:07 +01:00
|
|
|
|
2022-02-07 17:01:09 +01:00
|
|
|
class ConfigModelTreeItem;
|
2017-09-05 13:55:08 +02:00
|
|
|
|
|
|
|
|
class ConfigModel : public Utils::TreeModel<>
|
2016-01-27 10:22:07 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2016-10-10 09:49:46 +10:00
|
|
|
enum Roles {
|
2017-09-14 15:18:50 +02:00
|
|
|
ItemIsAdvancedRole = Qt::UserRole,
|
2022-10-17 13:28:59 +02:00
|
|
|
ItemIsInitialRole,
|
|
|
|
|
ItemIsUserNew,
|
2016-10-10 09:49:46 +10:00
|
|
|
};
|
|
|
|
|
|
2021-02-24 14:33:38 +01:00
|
|
|
struct DataItem {
|
2022-02-07 17:01:09 +01:00
|
|
|
bool operator==(const DataItem &other) const {
|
2021-12-28 21:42:29 +01:00
|
|
|
return key == other.key && isInitial == other.isInitial;
|
2021-02-24 14:33:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataItem() {}
|
2022-02-07 17:01:09 +01:00
|
|
|
DataItem(const CMakeConfigItem &cmi);
|
2021-02-24 14:33:38 +01:00
|
|
|
|
2022-02-07 17:01:09 +01:00
|
|
|
void setType(CMakeConfigItem::Type cmt);
|
2021-02-24 14:33:38 +01:00
|
|
|
|
2022-02-07 17:01:09 +01:00
|
|
|
QString typeDisplay() const;
|
2022-02-07 13:35:03 +01:00
|
|
|
|
2022-02-07 17:01:09 +01:00
|
|
|
CMakeConfigItem toCMakeConfigItem() const;
|
2021-02-25 15:21:01 +01:00
|
|
|
|
2023-02-28 19:43:15 +01:00
|
|
|
QString expandedValue(Utils::MacroExpander *expander);
|
|
|
|
|
|
2016-01-27 10:22:07 +01:00
|
|
|
enum Type { BOOLEAN, FILE, DIRECTORY, STRING, UNKNOWN};
|
|
|
|
|
|
|
|
|
|
QString key;
|
|
|
|
|
Type type = STRING;
|
2017-06-20 12:07:07 +02:00
|
|
|
bool isHidden = false;
|
2016-01-27 10:22:07 +01:00
|
|
|
bool isAdvanced = false;
|
2021-12-28 21:42:29 +01:00
|
|
|
bool isInitial = false;
|
2017-01-18 16:53:01 +01:00
|
|
|
bool inCMakeCache = false;
|
2017-09-27 12:28:11 +02:00
|
|
|
bool isUnset = false;
|
2016-01-27 10:22:07 +01:00
|
|
|
QString value;
|
|
|
|
|
QString description;
|
2016-10-10 09:49:46 +10:00
|
|
|
QStringList values;
|
2016-01-27 10:22:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
explicit ConfigModel(QObject *parent = nullptr);
|
2017-09-05 13:55:08 +02:00
|
|
|
~ConfigModel() override;
|
2016-01-27 10:22:07 +01:00
|
|
|
|
2017-09-05 13:55:08 +02:00
|
|
|
QVariant data(const QModelIndex &idx, int role) const final;
|
2022-02-01 11:08:14 +01:00
|
|
|
bool setData(const QModelIndex &idx, const QVariant &data, int role) final;
|
2016-01-27 10:22:07 +01:00
|
|
|
|
2016-05-15 15:57:17 +02:00
|
|
|
void appendConfiguration(const QString &key,
|
|
|
|
|
const QString &value = QString(),
|
|
|
|
|
const DataItem::Type type = DataItem::UNKNOWN,
|
2021-12-28 21:42:29 +01:00
|
|
|
bool isInitial = false,
|
2016-10-10 09:49:46 +10:00
|
|
|
const QString &description = QString(),
|
|
|
|
|
const QStringList &values = QStringList());
|
2017-09-28 11:32:39 +02:00
|
|
|
void setConfiguration(const CMakeConfig &config);
|
2021-02-24 14:33:38 +01:00
|
|
|
void setBatchEditConfiguration(const CMakeConfig &config);
|
2021-12-28 21:42:29 +01:00
|
|
|
void setInitialParametersConfiguration(const CMakeConfig &config);
|
2016-01-27 10:22:07 +01:00
|
|
|
void setConfiguration(const QList<DataItem> &config);
|
2021-12-28 21:42:29 +01:00
|
|
|
|
2022-02-01 16:37:52 +01:00
|
|
|
using KitConfiguration = QHash<QString, CMakeConfigItem>;
|
2021-12-28 21:42:29 +01:00
|
|
|
void setConfigurationFromKit(const KitConfiguration &kitConfig);
|
2020-04-02 14:49:05 +02:00
|
|
|
|
2016-01-27 10:22:07 +01:00
|
|
|
void flush();
|
2021-12-28 21:42:29 +01:00
|
|
|
void resetAllChanges(bool initialParameters = false);
|
2016-01-27 10:22:07 +01:00
|
|
|
|
2021-12-28 21:42:29 +01:00
|
|
|
bool hasChanges(bool initialParameters = false) const;
|
2016-01-27 10:22:07 +01:00
|
|
|
|
2017-09-14 15:36:18 +02:00
|
|
|
bool canForceTo(const QModelIndex &idx, const DataItem::Type type) const;
|
|
|
|
|
void forceTo(const QModelIndex &idx, const DataItem::Type type);
|
2017-09-14 13:16:10 +02:00
|
|
|
|
2017-09-27 12:28:11 +02:00
|
|
|
void toggleUnsetFlag(const QModelIndex &idx);
|
|
|
|
|
|
2022-01-28 18:16:23 +01:00
|
|
|
void applyKitValue(const QModelIndex &idx);
|
|
|
|
|
void applyInitialValue(const QModelIndex &idx);
|
|
|
|
|
|
2017-09-14 15:18:50 +02:00
|
|
|
static DataItem dataItemFromIndex(const QModelIndex &idx);
|
|
|
|
|
|
2017-09-29 23:34:52 +02:00
|
|
|
QList<DataItem> configurationForCMake() const;
|
2016-01-27 10:22:07 +01:00
|
|
|
|
2022-01-24 13:41:13 +01:00
|
|
|
Utils::MacroExpander *macroExpander() const;
|
|
|
|
|
void setMacroExpander(Utils::MacroExpander *newExpander);
|
2017-09-28 11:32:39 +02:00
|
|
|
|
2016-01-27 10:22:07 +01:00
|
|
|
private:
|
2022-01-28 18:16:23 +01:00
|
|
|
enum class KitOrInitial { Kit, Initial };
|
|
|
|
|
void applyKitOrInitialValue(const QModelIndex &idx, KitOrInitial ki);
|
|
|
|
|
|
2016-01-27 10:22:07 +01:00
|
|
|
class InternalDataItem : public DataItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
InternalDataItem(const DataItem &item);
|
|
|
|
|
|
2017-01-18 16:56:00 +01:00
|
|
|
QString currentValue() const;
|
2016-12-01 15:24:36 +01:00
|
|
|
|
|
|
|
|
bool isUserChanged = false;
|
|
|
|
|
bool isUserNew = false;
|
2016-01-27 10:22:07 +01:00
|
|
|
QString newValue;
|
2017-09-05 13:55:08 +02:00
|
|
|
QString kitValue;
|
2022-01-24 13:41:13 +01:00
|
|
|
QString initialValue;
|
2016-01-27 10:22:07 +01:00
|
|
|
};
|
|
|
|
|
|
2017-09-05 13:55:08 +02:00
|
|
|
void generateTree();
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
void setConfiguration(const QList<InternalDataItem> &config);
|
2016-01-27 10:22:07 +01:00
|
|
|
QList<InternalDataItem> m_configuration;
|
2021-12-28 21:42:29 +01:00
|
|
|
KitConfiguration m_kitConfiguration;
|
2022-01-24 13:41:13 +01:00
|
|
|
Utils::MacroExpander *m_macroExpander = nullptr;
|
2017-09-05 13:55:08 +02:00
|
|
|
|
|
|
|
|
friend class Internal::ConfigModelTreeItem;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ConfigModelTreeItem : public Utils::TreeItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ConfigModelTreeItem(ConfigModel::InternalDataItem *di = nullptr) : dataItem(di) {}
|
2018-11-04 23:09:41 +01:00
|
|
|
~ConfigModelTreeItem() override;
|
2017-09-05 13:55:08 +02:00
|
|
|
|
|
|
|
|
QVariant data(int column, int role) const final;
|
|
|
|
|
bool setData(int column, const QVariant &data, int role) final;
|
|
|
|
|
Qt::ItemFlags flags(int column) const final;
|
|
|
|
|
|
|
|
|
|
QString toolTip() const;
|
|
|
|
|
QString currentValue() const;
|
|
|
|
|
|
|
|
|
|
ConfigModel::InternalDataItem *dataItem;
|
2016-01-27 10:22:07 +01:00
|
|
|
};
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
} // CMakeProjectManager::Internal
|