В продолжение
извращений Flamer'a на тему БилдераАвтор: Flamer
Дата: 25.01.03
. Все то же самое, но для Qt4:
Пример использования:
/* Где-то в QDialog или QWidget */
PropertySwitcher ps;
ps << QString("enabled")
<< QVariant(true) // всем последующим объектам будет установлено enabled = true
<< _ui.detailFrame
<< QVariant(false) // всем последующим объектам будет установлено enabled = false
<< _ui.agencyList
<< _ui.agencyDeleteButton
<< QString("cursor")
<< QVariant::fromValue(QCursor(Qt::BusyCursor)) // всем последующим объектам будет установлен cursor = BusyCursor
<< this;
Сам класс /* тривиально, на самом-то деле
*/:
#ifndef PROPERTY_SWITCHER_H
#define PROPERTY_SWITCHER_H
#include <QWidget>
#include <QVariant>
class PropertySwitcher {
private:
QVariant _propertyValue;
QString _property;
public:
PropertySwitcher(){}
PropertySwitcher& operator<<(QWidget *w)
{
int i = w -> metaObject() -> indexOfProperty(_property.toAscii().constData());
if(i != -1)
w -> setProperty(_property.toAscii().constData(), _propertyValue);
return *this;
}
PropertySwitcher& operator<<(const QVariant &propertyValue)
{
_propertyValue = propertyValue;
return *this;
}
PropertySwitcher& operator<<(const QString &p)
{
_property = p;
return *this;
}
};
#endif
Работает практически со всеми свойствами объектов.