函数定义的规范-电子书包
1.receiveSocketCmds,receiveWebServiceCmds
这两个函数主要是从platform以及终端数据传回来之后,模拟成event的事件,再从wm里面传过来,按照对于用户事件的参考函数做法比如paintEvent,mouseMoveEvent,mousePressEvent等等,这两个函数改成socketEvent以及webserviceEvent可能更加合适。
2.setConfigFile
该函数用于从配置文档中读取相应的窗口属性以及对应的工具栏按钮等等,当时也没有多去细想,至少现在看来,这个set的称呼不太合适,如果说设置一个变量等等的话,马马虎虎还行。这个地方改成readConfigFile可能更加合适。
3.windowReturn(bool del=true)
在关闭某一个窗口的时候,我们采用windowReturn来关闭这个窗口,但是其违背了我们动词小写+名词的这种方式,所以这个地方改成closeWindow更加合适(但是需要确认qt是否已经有这样的closeWindow函数,可以在assistant里面看一下,如果没有的话,比较合适)。
4.initToolBar,initUI
5.派生类主要重写函数宏
基于BaseWindow的派生类很多,其有一个共同的特点,需要重写setupLayout,socketEvent,webserviceEvent,slotButtonClicked(该函数考虑信号和槽的使用习惯的话,可以改成buttonClicked)
#define DECLARE_DERIVED_FUNCTION(Class)\ public:\ Class(QWidget* parent = 0);\ virtual ~Class(); \ \ protected: \ virtual void setupLayout(); \ \ protected slots: \ virtual void buttonClicked(int) ; \ virtual void closeWindow(bool del = true); \ virtual void socketEvent(QEvent*); \ virtual void webserviceEvent(QEvent*); \ \ protected: \ virtual void receiveCmd(QEvent*); \ virtual void sendCmd(int cmds, int flags, const QVariant &data); \ virtual void sendCmd(const QString &id, int cmds, int flags, const QVariant &data) ; \ \ public: \ virtual int string2int(const QString&); \ virtual void readConfigFile(const QString& file); \ virtual void resetLanguage(); \
这个宏我们需要在定义头文件的时候进行声明,其定义可以放在Global.h文件里面。
但是还有一些函数并不是在每一个派生类里面都需要用到,如果不用到的话,我们直接可以用一个空的宏定义就可以了。
#define DECLARE_DEFAULT_FUNCTION(Class,Function,__VA_ARGS__) \ void Class::Function(__VA_ARGS__) { \ return BaseWindow::Function(__VA_ARGS__);\ }
__VA_ARGS__表示一个可变参数宏,需要编译器支持C99特性。一般情况gcc是可以支持C99。
6.字体类使用宏定义
#define DECLARE_FONT(s) \ private: \ static QFont m_font##s; \ static bool m_font##s_ok; \ public: \ static const QFont& getFont##s();
#define DECLARE_FONT_FUNCTION(s) \ QFont BaseFont::m_font##s; \ bool BaseFont::m_font##s_ok = false; \ const QFont& BaseFont::getFont##s() { \ if(!m_font##s_ok) { \ m_font##s.setFamily("Microsoft YaHei"); \ m_font##s.setPointSize(s); \ m_font##s.setWeight(58); \ m_font##s.setStyleHint(QFont::Monospace, QFont::PreferAntialias); \ m_font##s_ok = true; \ } \ return m_font##s;\ }