forked from qt-creator/qt-creator
QmlDesigner: Fix build
- remove useless unique pointer - remove const when values are changed - add QVariant include - explicitly delete the copy constructor and copy assignment operator so the std::unique_ptr in the map can not copied by accident (create compile problems on newer Visual Studio Compilers) 565449 introduced it Change-Id: If10f8191ee9b09c7bcdacd328fb495449b49f219 Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "nodeinstanceglobal.h"
|
#include "nodeinstanceglobal.h"
|
||||||
|
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
namespace QmlDesigner
|
namespace QmlDesigner
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -48,15 +49,18 @@ bool DSThemeGroup::addProperty(ThemeId theme, const ThemeProperty &prop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!m_values.contains(prop.name))
|
if (!m_values.contains(prop.name))
|
||||||
m_values[prop.name] = make_unique<ThemeValues>();
|
m_values[prop.name] = {};
|
||||||
|
|
||||||
const auto &tValues = m_values.at(prop.name);
|
auto &tValues = m_values.at(prop.name);
|
||||||
if (tValues->contains(theme)) {
|
if (tValues.contains(theme)) {
|
||||||
qCDebug(dsLog) << "Add property failed. Duplicate property name." << prop;
|
qCDebug(dsLog) << "Add property failed. Duplicate property name." << prop;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
tValues->insert({theme, {prop.value, prop.isBinding}});
|
tValues.emplace(std::piecewise_construct,
|
||||||
|
std::forward_as_tuple(theme),
|
||||||
|
std::forward_as_tuple(prop.value, prop.isBinding));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,8 +70,8 @@ std::optional<ThemeProperty> DSThemeGroup::propertyValue(ThemeId theme, const Pr
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
const auto &tValues = m_values.at(name);
|
const auto &tValues = m_values.at(name);
|
||||||
const auto itr = tValues->find(theme);
|
const auto itr = tValues.find(theme);
|
||||||
if (itr != tValues->end()) {
|
if (itr != tValues.end()) {
|
||||||
auto &[value, isBindind] = itr->second;
|
auto &[value, isBindind] = itr->second;
|
||||||
return ThemeProperty{name, value, isBindind};
|
return ThemeProperty{name, value, isBindind};
|
||||||
}
|
}
|
||||||
@@ -93,13 +97,15 @@ void DSThemeGroup::updateProperty(ThemeId theme, PropertyName newName, const The
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto &tValues = m_values.at(prop.name);
|
auto &tValues = m_values.at(prop.name);
|
||||||
const auto itr = tValues->find(theme);
|
const auto itr = tValues.find(theme);
|
||||||
if (itr == tValues->end()) {
|
if (itr == tValues.end()) {
|
||||||
qCDebug(dsLog) << "Property update failure. No property for the theme" << theme << prop;
|
qCDebug(dsLog) << "Property update failure. No property for the theme" << theme << prop;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tValues->at(theme) = {prop.value, prop.isBinding};
|
auto &entry = tValues.at(theme);
|
||||||
|
entry.value = prop.value;
|
||||||
|
entry.isBinding = prop.isBinding;
|
||||||
if (newName != prop.name) {
|
if (newName != prop.name) {
|
||||||
m_values[newName] = std::move(tValues);
|
m_values[newName] = std::move(tValues);
|
||||||
m_values.erase(prop.name);
|
m_values.erase(prop.name);
|
||||||
@@ -115,9 +121,9 @@ size_t DSThemeGroup::count(ThemeId theme) const
|
|||||||
{
|
{
|
||||||
return std::accumulate(m_values.cbegin(),
|
return std::accumulate(m_values.cbegin(),
|
||||||
m_values.cend(),
|
m_values.cend(),
|
||||||
0,
|
0ull,
|
||||||
[theme](size_t c, const GroupProperties::value_type &p) {
|
[theme](size_t c, const GroupProperties::value_type &p) {
|
||||||
return c + (p.second->contains(theme) ? 1 : 0);
|
return c + (p.second.contains(theme) ? 1 : 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,22 +134,19 @@ size_t DSThemeGroup::count() const
|
|||||||
|
|
||||||
void DSThemeGroup::removeTheme(ThemeId theme)
|
void DSThemeGroup::removeTheme(ThemeId theme)
|
||||||
{
|
{
|
||||||
for (auto itr = m_values.cbegin(); itr != m_values.cend();) {
|
for (auto itr = m_values.begin(); itr != m_values.end();) {
|
||||||
itr->second->erase(theme);
|
itr->second.erase(theme);
|
||||||
itr = itr->second->size() == 0 ? m_values.erase(itr) : std::next(itr);
|
itr = itr->second.size() == 0 ? m_values.erase(itr) : std::next(itr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DSThemeGroup::duplicateValues(ThemeId from, ThemeId to)
|
void DSThemeGroup::duplicateValues(ThemeId from, ThemeId to)
|
||||||
{
|
{
|
||||||
for (auto itr = m_values.cbegin(); itr != m_values.cend(); ++itr) {
|
for (auto itr = m_values.begin(); itr != m_values.end(); ++itr) {
|
||||||
const auto &[propName, values] = *itr;
|
auto &[propName, values] = *itr;
|
||||||
if (!values)
|
auto fromValueItr = values.find(from);
|
||||||
continue;
|
if (fromValueItr != values.end())
|
||||||
|
values[to] = fromValueItr->second;
|
||||||
auto fromValueItr = values->find(from);
|
|
||||||
if (fromValueItr != values->end())
|
|
||||||
(*values)[to] = fromValueItr->second;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,11 +165,11 @@ void DSThemeGroup::decorate(ThemeId theme, ModelNode themeNode)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto itr = m_values.cbegin(); itr != m_values.cend(); ++itr) {
|
for (auto itr = m_values.begin(); itr != m_values.end(); ++itr) {
|
||||||
const auto &[propName, values] = *itr;
|
auto &[propName, values] = *itr;
|
||||||
auto themeValue = values->find(theme);
|
auto themeValue = values.find(theme);
|
||||||
if (themeValue != values->end()) {
|
if (themeValue != values.end()) {
|
||||||
const auto &propData = themeValue->second;
|
auto &propData = themeValue->second;
|
||||||
if (propData.isBinding) {
|
if (propData.isBinding) {
|
||||||
auto bindingProp = groupNode.bindingProperty(propName);
|
auto bindingProp = groupNode.bindingProperty(propName);
|
||||||
if (bindingProp)
|
if (bindingProp)
|
||||||
|
|||||||
@@ -16,12 +16,19 @@ class DSThemeGroup
|
|||||||
{
|
{
|
||||||
struct PropertyData
|
struct PropertyData
|
||||||
{
|
{
|
||||||
|
PropertyData() = default;
|
||||||
|
template<typename Variant>
|
||||||
|
PropertyData(Variant &&value, bool isBinding)
|
||||||
|
: value{std::forward<Variant>(value)}
|
||||||
|
, isBinding{isBinding}
|
||||||
|
{}
|
||||||
|
|
||||||
QVariant value;
|
QVariant value;
|
||||||
bool isBinding = false;
|
bool isBinding = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ThemeValues = std::map<ThemeId, PropertyData>;
|
using ThemeValues = std::map<ThemeId, PropertyData>;
|
||||||
using GroupProperties = std::map<PropertyName, std::unique_ptr<ThemeValues>>;
|
using GroupProperties = std::map<PropertyName, ThemeValues>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DSThemeGroup(GroupType type);
|
DSThemeGroup(GroupType type);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Q_LOGGING_CATEGORY(dsLog, "qtc.designer.designSystem", QtInfoMsg)
|
Q_LOGGING_CATEGORY(dsLog, "qtc.designer.designSystem", QtInfoMsg)
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ public:
|
|||||||
DSThemeManager();
|
DSThemeManager();
|
||||||
~DSThemeManager();
|
~DSThemeManager();
|
||||||
|
|
||||||
|
DSThemeManager(const DSThemeManager&) = delete;
|
||||||
|
DSThemeManager& operator=(const DSThemeManager&) = delete;
|
||||||
|
|
||||||
|
DSThemeManager(DSThemeManager&&) = default;
|
||||||
|
DSThemeManager& operator=(DSThemeManager&&) = default;
|
||||||
|
|
||||||
std::optional<ThemeId> addTheme(const ThemeName &themeName);
|
std::optional<ThemeId> addTheme(const ThemeName &themeName);
|
||||||
std::optional<ThemeId> themeId(const ThemeName &themeName) const;
|
std::optional<ThemeId> themeId(const ThemeName &themeName) const;
|
||||||
void removeTheme(ThemeId id);
|
void removeTheme(ThemeId id);
|
||||||
|
|||||||
Reference in New Issue
Block a user