参考:
开始有点迷茫,感觉它们的关系有点象工人与工头,manager具体来实现,但需foctory来调配.
此比喻可能有点不妥当,欢迎留言指更
class FilePathManager : public QtAbstractPropertyManager
{
Q_OBJECT
public:
FilePathManager(QObject *parent = 0) : QtAbstractPropertyManager(parent){ }
QString value(const QtProperty *property) const;
QString filter(const QtProperty *property) const;
public slots:
void setValue(QtProperty *property, const QString &val);
void setFilter(QtProperty *property, const QString &fil);
signals:
void valueChanged(QtProperty *property, const QString &val);
void filterChanged(QtProperty *property, const QString &fil);
protected:
virtual QString valueText(const QtProperty *property) const { return value(property); }
virtual void initializeProperty(QtProperty *property) { theValues[property] = Data(); }
virtual void uninitializeProperty(QtProperty *property) { theValues.remove(property); }
private:
struct Data
{
QString value;
QString filter;
};
mutable QMap theValues;
};
class DecoratedDoublePropertyManager : public QtDoublePropertyManager
{
Q_OBJECT
public:
DecoratedDoublePropertyManager(QObject *parent = 0);
~DecoratedDoublePropertyManager();
QString prefix(const QtProperty *property) const;
QString suffix(const QtProperty *property) const;
public Q_SLOTS:
void setPrefix(QtProperty *property, const QString &prefix);
void setSuffix(QtProperty *property, const QString &suffix);
Q_SIGNALS:
void prefixChanged(QtProperty *property, const QString &prefix);
void suffixChanged(QtProperty *property, const QString &suffix);
protected:
QString valueText(const QtProperty *property) const;
virtual void initializeProperty(QtProperty *property);
virtual void uninitializeProperty(QtProperty *property);
private:
struct Data {
QString prefix;
QString suffix;
};
QMap propertyToData;
};
/*********************************************/
class DecoratedDoubleSpinBoxFactory : public QtAbstractEditorFactory
{
Q_OBJECT
public:
DecoratedDoubleSpinBoxFactory(QObject *parent = 0);
~DecoratedDoubleSpinBoxFactory();
protected:
void connectPropertyManager(DecoratedDoublePropertyManager *manager);
QWidget *createEditor(DecoratedDoublePropertyManager *manager, QtProperty *property, QWidget *parent);
void disconnectPropertyManager(DecoratedDoublePropertyManager *manager);
private slots:
void slotPrefixChanged(QtProperty *property, const QString &prefix);
void slotSuffixChanged(QtProperty *property, const QString &prefix);
void slotEditorDestroyed(QObject *object);
private:
/* We delegate responsibilities for QtDoublePropertyManager, which is a base class
of DecoratedDoublePropertyManager to appropriate QtDoubleSpinBoxFactory */
QtDoubleSpinBoxFactory *originalFactory;
QMap > createdEditors;
QMap editorToProperty;
};
class FileEditFactory : public QtAbstractEditorFactory
{
Q_OBJECT
public:
FileEditFactory(QObject *parent = 0)
: QtAbstractEditorFactory(parent)
{ }
virtual ~FileEditFactory();
protected:
virtual void connectPropertyManager(FilePathManager *manager);
virtual QWidget *createEditor(FilePathManager *manager, QtProperty *property,
QWidget *parent);
virtual void disconnectPropertyManager(FilePathManager *manager);
private slots:
void slotPropertyChanged(QtProperty *property, const QString &value);
void slotFilterChanged(QtProperty *property, const QString &filter);
void slotSetValue(const QString &value);
void slotEditorDestroyed(QObject *object);
private:
QMap > theCreatedEditors;
QMap theEditorToProperty;
};
阅读(1738) | 评论(0) | 转发(0) |