Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QtPropertyBrowser: resizeToContent(), bold property text, read-only handling #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions qtpropertybrowser/src/qtpropertybrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class QtPropertyPrivate
QtPropertyPrivate(QtAbstractPropertyManager *manager)
: m_enabled(true),
m_modified(false),
m_bold(false),
m_manager(manager) {}
QtProperty *q_ptr;

Expand All @@ -71,6 +72,7 @@ class QtPropertyPrivate
QString m_name;
bool m_enabled;
bool m_modified;
bool m_bold;

QtAbstractPropertyManager * const m_manager;
};
Expand Down Expand Up @@ -264,6 +266,16 @@ bool QtProperty::isModified() const
return d_ptr->m_modified;
}

/*!
Returns whether the property is bold.

\sa setBold()
*/
bool QtProperty::isBold() const
{
return d_ptr->m_bold;
}

/*!
Returns whether the property has a value.

Expand Down Expand Up @@ -399,6 +411,20 @@ void QtProperty::setModified(bool modified)
propertyChanged();
}

/*!
Sets the property's bold state according to the passed \a bold value.

\sa isBold()
*/
void QtProperty::setBold(bool bold)
{
if (d_ptr->m_bold == bold)
return;

d_ptr->m_bold = bold;
propertyChanged();
}

/*!
Appends the given \a property to this property's subproperties.

Expand Down
2 changes: 2 additions & 0 deletions qtpropertybrowser/src/qtpropertybrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class QT_QTPROPERTYBROWSER_EXPORT QtProperty
QString propertyName() const;
bool isEnabled() const;
bool isModified() const;
bool isBold() const;

bool hasValue() const;
QIcon valueIcon() const;
Expand All @@ -98,6 +99,7 @@ class QT_QTPROPERTYBROWSER_EXPORT QtProperty
void setPropertyName(const QString &text);
void setEnabled(bool enable);
void setModified(bool modified);
void setBold(bool bold);

void addSubProperty(QtProperty *property);
void insertSubProperty(QtProperty *property, QtProperty *afterProperty);
Expand Down
48 changes: 42 additions & 6 deletions qtpropertybrowser/src/qtpropertymanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ QtMetaEnumProvider::QtMetaEnumProvider()
QtMetaEnumWrapper::staticMetaObject.propertyOffset() + 0);
m_policyEnum = p.enumerator();
const int keyCount = m_policyEnum.keyCount();
for (int i = 0; i < keyCount; i++)
for (int i = 0; i < keyCount; ++i)
m_policyEnumNames << QLatin1String(m_policyEnum.key(i));

initLocale();
Expand All @@ -522,7 +522,7 @@ QSizePolicy::Policy QtMetaEnumProvider::indexToSizePolicy(int index) const
int QtMetaEnumProvider::sizePolicyToIndex(QSizePolicy::Policy policy) const
{
const int keyCount = m_policyEnum.keyCount();
for (int i = 0; i < keyCount; i++)
for (int i = 0; i < keyCount; ++i)
if (indexToSizePolicy(i) == policy)
return i;
return -1;
Expand Down Expand Up @@ -891,7 +891,7 @@ void QtIntPropertyManager::setSingleStep(QtProperty *property, int step)
/*!
Sets read-only status of the property.

\sa QtIntPropertyManager::setReadOnly
\sa QtIntPropertyManager::isReadOnly
*/
void QtIntPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
{
Expand Down Expand Up @@ -1165,7 +1165,7 @@ void QtDoublePropertyManager::setSingleStep(QtProperty *property, double step)
/*!
Sets read-only status of the property.

\sa QtDoublePropertyManager::setReadOnly
\sa QtDoublePropertyManager::isReadOnly
*/
void QtDoublePropertyManager::setReadOnly(QtProperty *property, bool readOnly)
{
Expand Down Expand Up @@ -1526,7 +1526,7 @@ void QtStringPropertyManager::setEchoMode(QtProperty *property, EchoMode echoMod
/*!
Sets read-only status of the property.

\sa QtStringPropertyManager::setReadOnly
\sa QtStringPropertyManager::isReadOnly
*/
void QtStringPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
{
Expand All @@ -1543,7 +1543,7 @@ void QtStringPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
it.value() = data;

emit propertyChanged(property);
emit readOnlyChanged(property, data.readOnly);
emit readOnlyChanged(property, data.echoMode);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh? Is this correct?

}

/*!
Expand Down Expand Up @@ -4821,6 +4821,7 @@ class QtEnumPropertyManagerPrivate
{
Data() : val(-1) {}
int val;
bool readOnly;
QStringList enumNames;
QMap<int, QIcon> enumIcons;
};
Expand Down Expand Up @@ -5062,6 +5063,41 @@ void QtEnumPropertyManager::setEnumIcons(QtProperty *property, const QMap<int, Q
emit propertyChanged(property);
}

/*!
Returns read-only status of the property.

When property is read-only it's value can be selected and copied from editor but not modified.

\sa QtEnumPropertyManager::setReadOnly
*/
bool QtEnumPropertyManager::isReadOnly(const QtProperty *property) const
{
return getData<bool>(d_ptr->m_values, &QtEnumPropertyManagerPrivate::Data::readOnly, property, false);
}

/*!
Sets read-only status of the property.

\sa QtEnumPropertyManager::isReadOnly
*/
void QtEnumPropertyManager::setReadOnly(QtProperty *property, bool readOnly)
{
const QtEnumPropertyManagerPrivate::PropertyValueMap::iterator it = d_ptr->m_values.find(property);
if (it == d_ptr->m_values.end())
return;

QtEnumPropertyManagerPrivate::Data data = it.value();

if (data.readOnly == readOnly)
return;

data.readOnly = readOnly;
it.value() = data;

emit propertyChanged(property);
emit readOnlyChanged(property, data.readOnly);
}

/*!
\reimp
*/
Expand Down
5 changes: 4 additions & 1 deletion qtpropertybrowser/src/qtpropertymanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public Q_SLOTS:
void valueChanged(QtProperty *property, const QString &val);
void regExpChanged(QtProperty *property, const QRegExp &regExp);
void echoModeChanged(QtProperty *property, const int);
void readOnlyChanged(QtProperty *property, bool);
void readOnlyChanged(QtProperty *property, bool readOnly);

protected:
QString valueText(const QtProperty *property) const;
Expand Down Expand Up @@ -585,15 +585,18 @@ class QT_QTPROPERTYBROWSER_EXPORT QtEnumPropertyManager : public QtAbstractPrope
int value(const QtProperty *property) const;
QStringList enumNames(const QtProperty *property) const;
QMap<int, QIcon> enumIcons(const QtProperty *property) const;
bool isReadOnly(const QtProperty *property) const;

public Q_SLOTS:
void setValue(QtProperty *property, int val);
void setEnumNames(QtProperty *property, const QStringList &names);
void setEnumIcons(QtProperty *property, const QMap<int, QIcon> &icons);
void setReadOnly(QtProperty *property, bool readOnly);
Q_SIGNALS:
void valueChanged(QtProperty *property, int val);
void enumNamesChanged(QtProperty *property, const QStringList &names);
void enumIconsChanged(QtProperty *property, const QMap<int, QIcon> &icons);
void readOnlyChanged(QtProperty *property, bool readOnly);
protected:
QString valueText(const QtProperty *property) const;
QIcon valueIcon(const QtProperty *property) const;
Expand Down
11 changes: 11 additions & 0 deletions qtpropertybrowser/src/qttreepropertybrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,17 @@ void QtTreePropertyBrowser::editItem(QtBrowserItem *item)
d_ptr->editItem(item);
}

/*!
Ensure that the column width fits the current content size. Useful to ensure that
as much as possible is visible for the user based on the current content, while still
allowing for the overall resize mode to be QHeaderView::Interactive for the
user to adjust individually as needed.
*/
void QtTreePropertyBrowser::resizeToContent() const
{
d_ptr->m_treeWidget->header()->resizeSections(QHeaderView::ResizeToContents);
}

#if QT_VERSION >= 0x040400
QT_END_NAMESPACE
#endif
Expand Down
2 changes: 2 additions & 0 deletions qtpropertybrowser/src/qttreepropertybrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class QT_QTPROPERTYBROWSER_EXPORT QtTreePropertyBrowser : public QtAbstractPrope

void editItem(QtBrowserItem *item);

void resizeToContent() const;

Q_SIGNALS:

void collapsed(QtBrowserItem *item);
Expand Down