C++ (Qt)class MyLineEdit : public QLineEdit { Q_OBJECTpublic: MyLineEdit( QWidget * parent ): #include MySlotSignals.h };
C++ (Qt)template <class T>class MyControl <T> : public T {..};
C++ (Qt)MyControl <MyLineEdit> * cnt1 = new...MyControl <MyTextEdit> * cnt2 = new ...
#ifndef WBUTTON_H#define WBUTTON_H#include "wcinculdes.h"#include <QPushButton>typedef QPushButton SuperClass;class WButton : public SuperClass, public PluginInterface{ Q_OBJECT Q_INTERFACES( PluginInterface )#include "wcontrol.h" // всё общее для разных контролов ...... здесь объявления специализированных методов кнопки};
C++ (Qt)#include "common_controls.h"#include <QPushButton> class WButton : public QPushButton, public PluginInterface{ Q_OBJECT Q_INTERFACES( PluginInterface ) COMMON_CONTROL(QPushButton)public: ...} // common_controls.h: #define COMMON_CONTROL(BaseClass) \signals: \ void mySignal(); \\public slots: \ void someSlot() \ { \ ##BaseClass::bla(); \ }
C++ (Qt)#define COMMON_CONTROL(BaseClass, DerivedClass) \private: \ friend class Impl<BaseClass, DerivedClass>; \ Impl<BaseClass, DerivedClass> *commonImpl; \ void initCommonImpl() \ { \ commonImpl = new Impl<BaseClass, DerivedClass>(this); \ } \signals: \ void mySignal(); \ \public slots: \ void mySlot() \ { \ commonImpl->mySlot(); \ } template<typename Base, typename Derived>class Impl{public: Impl(Derived *parent): m_parent(parent) {} virtual ~Impl() {} void mySlot() { reinterpret_cast<Base*>(m_parent)->mySlot(); } private: Derived *m_parent;}; class WButton: public QPushButton, public PluginInterface{ Q_OBJECT Q_INTERFACES( PluginInterface ) COMMON_CONTROL(QPushButton, WButton)public: WButton() { initCommonImpl(); }};
C++ (Qt)class MyLineEdit : public QLineEdit, public Common
C++ (Qt)class MyLineEdit : public QLineEdit, public Common{public: ... private slots: void onTextChanged( const QString &val ) { commonMethodText( val ); } void onReturnPressed() { commonMethodReturn(); }};