QtTreePropertyBrowser -Qt5
立即下载
资源介绍:
qtpropertybrowser Qt5 sources
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qtpropertymanager.h"
#include "qtpropertybrowserutils_p.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if defined(Q_CC_MSVC)
# pragma warning(disable: 4786) /* MS VS 6: truncating debug info after 255 characters */
#endif
QT_BEGIN_NAMESPACE
template
static void setSimpleMinimumData(PrivateData *data, const Value &minVal)
{
data->minVal = minVal;
if (data->maxVal < data->minVal)
data->maxVal = data->minVal;
if (data->val < data->minVal)
data->val = data->minVal;
}
template
static void setSimpleMaximumData(PrivateData *data, const Value &maxVal)
{
data->maxVal = maxVal;
if (data->minVal > data->maxVal)
data->minVal = data->maxVal;
if (data->val > data->maxVal)
data->val = data->maxVal;
}
template
static void setSizeMinimumData(PrivateData *data, const Value &newMinVal)
{
data->minVal = newMinVal;
if (data->maxVal.width() < data->minVal.width())
data->maxVal.setWidth(data->minVal.width());
if (data->maxVal.height() < data->minVal.height())
data->maxVal.setHeight(data->minVal.height());
if (data->val.width() < data->minVal.width())
data->val.setWidth(data->minVal.width());
if (data->val.height() < data->minVal.height())
data->val.setHeight(data->minVal.height());
}
template
static void setSizeMaximumData(PrivateData *data, const Value &newMaxVal)
{
data->maxVal = newMaxVal;
if (data->minVal.width() > data->maxVal.width())
data->minVal.setWidth(data->maxVal.width());
if (data->minVal.height() > data->maxVal.height())
data->minVal.setHeight(data->maxVal.height());
if (data->val.width() > data->maxVal.width())
data->val.setWidth(data->maxVal.width());
if (data->val.height() > data->maxVal.height())
data->val.setHeight(data->maxVal.height());
}
template
static SizeValue qBoundSize(const SizeValue &minVal, const SizeValue &val, const SizeValue &maxVal)
{
SizeValue croppedVal = val;
if (minVal.width() > val.width())
croppedVal.setWidth(minVal.width());
else if (maxVal.width() < val.width())
croppedVal.setWidth(maxVal.width());
if (minVal.height() > val.height())
croppedVal.setHeight(minVal.height());
else if (maxVal.height() < val.height())
croppedVal.setHeight(maxVal.height());
return croppedVal;
}
// Match the exact signature of qBound for VS 6.
QSize qBound(QSize minVal, QSize val, QSize maxVal)
{
return qBoundSize(minVal, val, maxVal);
}
QSizeF qBound(QSizeF minVal, QSizeF val, QSizeF maxVal)
{
return qBoundSize(minVal, val, maxVal);
}
namespace {
namespace {
template
void orderBorders(Value &minVal, Value &maxVal)
{
if (minVal > maxVal)
qSwap(minVal, maxVal);
}
template
static void orderSizeBorders(Value &minVal, Value &maxVal)
{
Value fromSize = minVal;
Value toSize = maxVal;
if (fromSize.width() > toSize.width()) {
fromSize.setWidth(maxVal.width());
toSize.setWidth(minVal.width());
}
if (fromSize.height() > toSize.height()) {
fromSize.setHeight(maxVal.height());
toSize.setHeight(minVal.height());
}
minVal = fromSize;
maxVal = toSize;
}
void orderBorders(QSize &minVal, QSize &maxVal)
{
orderSizeBorders(minVal, maxVal);
}
void orderBorders(QSizeF &minVal, QSizeF &maxVal)
{
orderSizeBorders(minVal, maxVal);
}
}
}
////////
template
static Value getData(const QHash &propertyMap,
Value PrivateData::*data,
const QtProperty *property, const Value &defaultValue = Value())
{
const auto it = propertyMap.constFind(property);
if (it == propertyMap.constEnd())
return defaultValue;
return it.value().*data;
}
template
static Value getValue(const QHash &propertyMap,
const QtProperty *property, const Value &defaultValue = Value())
{
return getData(propertyMap, &PrivateData::val, property, defaultValue);
}
template
static Value getMinimum(const QHash &propertyMap,
const QtProperty *property, const Value &defaultValue = Value())
{
return getData(propertyMap, &PrivateData::minVal, property, defaultValue);
}
template
static Value getMaximum(const QHash &propertyMap,
const QtProperty *property, const Value &defaultValue = Value())
{
return getData(propertyMap, &PrivateData::maxVal, property, defaultValue);
}
template
static void setSimpleValue(QHash &propertyMap,
PropertyManager *manager,
void (PropertyManager::*propertyChangedSignal)(QtProperty *),
void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
QtProperty *property, const Value &val)
{
const auto it = propertyMap.find(property);
if (it == propertyMap.end())
return;
if (it.value() == val)
return;
it.value() = val;
emit (manager->*propertyChangedSignal)(property);
emit (manager->*valueChangedSignal)(property, val);
}
template
static void setValueInRange(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
void (PropertyManager::*propertyChangedSignal)(QtProperty *),
void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
QtProperty *property, const Value &val,
void (PropertyManagerPrivate::*setSubPropertyValue)(QtProperty *, ValueChangeParameter))
{
const auto it = managerPrivate->m_values.find(property);
if (it == managerPrivate->m_values.end())
return;
auto &data = it.value();
if (data.val == val)
return;
const Value oldVal = data.val;
data.val = qBound(data.minVal, val, data.maxVal);
if (data.val == oldVal)
return;
if (setSubPropertyValue)
(managerPrivate->*setSubPropertyValue)(property, data.val);
emit (manager->*propertyChangedSignal)(property);
emit (manager->*valueChangedSignal)(property, data.val);
}
template
static void setBorderValues(PropertyManager *manager, PropertyManagerPrivate *managerPrivate,
void (PropertyManager::*propertyChangedSignal)(QtProperty *),
void (PropertyManager::*valueChangedSignal)(QtProperty *, ValueChangeParameter),
void (PropertyManager::*rangeChangedSignal)(QtProperty *, ValueChangeParameter, ValueChangeParameter),
QtProperty *property, ValueChangeParameter minVal, ValueChangeParameter maxVal,
void (Prop