#ifndef QTPAPPLICATION_H #define QTPAPPLICATION_H #include #include "qTpFunctions.h" //#include "QTadpoleCallback.h" //#include "QTpFilter.h" #include "tpGuiHeader.h" #include "QTpProcess.h" //#include //#include #include "QTpAction.h" #include "QTpComboBox.h" #include "QTpPushButton.h" #include "QTpSpinBox.h" #include "QTpRadioButton.h" #include "QTpCheckBox.h" #include "QTpTabWidget.h" #include "QTpListWidget.h" #include "QTpStackedWidget.h" #include #include #define ADD_FILTER_MEMBER(cls) protected: \ class cls##* m_pFilter; class QTpApplication : public QtSingleApplication { Q_OBJECT public: QTpApplication(class QTpFilter* pfilterObj, int& argc, char** argv); ~QTpApplication(); virtual int OnAppIn(int ncode); virtual int OnAppOut(int ncode); virtual int Exec(bool bShow = true); QWidget* GetWidget(const QString& sKey); bool DelWidget(const QString& sKey); bool DelWidget(QWidget* pWdg); //QList FindWidgets(const QString& objName); //QList FindObjects(const QString& objName); QTpWidgetList FindWidgets(const QString& objName, QObject* parent = NULL); QTpWidgetList FindWidgets(const QRegExp& regExp, QObject* parent = NULL); QTpObjectList FindObjects(const QString& objName, QObject* parent = NULL); QJsonObject AppJson(); QString MainWindowName(); void SetEditText(const QString& name, const QString& text, QObject* parent = NULL); void SetValue(const QString& name, const QVariant& text, QObject* parent = NULL); QString GetEditText(const QString& name, QObject* parent = NULL); void SetComboBoxTextData(const QString& name, const QTpStrStrMap& textData, QObject* parent = NULL); void ShlftFullScreen(const QString& name, QObject* parent = NULL); void ShlftFullScreen(QObject* pChild); QWidget* MainWidget(); void WidgetUpdate(QWidget* p) { emit sgUpdateWidget(p); } QString DllPath() { return m_dllPath; } QStringList DllPaths() { return m_dllPaths; } QString MainPath() { return m_mainPath; } static QObject* TopParent(QObject* p) { if (NULL != p) { while (NULL != p->parent()) { p = p->parent(); } } return p; } static QString CurrentPath() { return TpExeFileToPath(applicationFilePath()); } static void AddPluginsPath(char* filePath) { QString szPath = TpExeFileToPath(QString::fromLocal8Bit(filePath)); QApplication::addLibraryPath(szPath + "plugins"); } void SetLinkedSlider(/*class QLineEdit* pEdit*/class QObject* pWdg); void SetLinkedValueEdit(class QSlider* pSlider, int value); void SetJson2TableWidget(const QJsonObject& json); bool SetFilter(QObject* pObject); // void connectSignals(); private: Q_SIGNALS : void sgUpdateWidget(QWidget*); private Q_SLOTS: void OnUpdateWidget(QWidget* pWgt); protected: QString m_mainPath; QString m_dllPath; QStringList m_dllPaths; private: class QTpUiContainer* m_pContainer; ADD_FILTER_MEMBER(QTpFilter) }; #define INIT_FILTER_OBJ(obj) m_pFilter = obj; obj->SetApp(this); //#define SET_FILTER_MEMBER(obj) m_pFilter = obj; //#define CALL_SET_APP_FUNC(obj) obj->SetApp(this); inline bool open_widget_by_property(QObject* pObj, QTpApplication* pApp, bool bDoubleClicked = false) { if (NULL == pObj || NULL == pApp) { return false; } QString uiFile; if (bDoubleClicked) { uiFile = tp_check_string_property(TP_PROP_STRING_DOUBLE_CLICKED_TO_OPEN_UI_FILE, pObj); } else { uiFile = tp_check_string_property(TP_PROP_STRING_CLICKED_TO_OPEN_UI_FILE, pObj); } if (uiFile.isEmpty()) { return false; } QWidget* pWg = pApp->GetWidget(uiFile); if (NULL == pWg) { return false; } pWg->setProperty(TP_PROP_STRING_OPENED_BY_OBJECT, pObj->objectName()); if (tp_check_bool_property(TP_PROP_BOOL_STAY_ON_TOP, pObj)){ pWg->setWindowFlags(Qt::WindowStaysOnTopHint); } pWg->show(); return true; } inline bool clicked_to_show_hide_widget_by_property(QObject* pObj, QTpApplication* pApp) { if (NULL == pObj || NULL == pApp) { return false; } QString objName = tp_check_string_property(TP_PROP_STRING_CLICKED_TO_SHOW_DOCKWIDGET, pObj); if (objName.isEmpty()) { return false; } QWidgetList wList = pApp->FindWidgets(objName); if (0 == wList.size()) { return false; } for (QWidgetList::iterator it = wList.begin(); it != wList.end(); ++it) { QDockWidget *pDock = qobject_cast(*it); if (NULL == pDock) { continue; } if (pDock->isHidden()) { pDock->show(); } else { pDock->hide(); } } // return true; } #endif // QTPAPPLICATION_H