From 0041a19397c3b96ce61b28926599c29435ec08e6 Mon Sep 17 00:00:00 2001 From: aquiles Date: Mon, 6 Dec 2010 19:16:00 +0100 Subject: [PATCH] Changed: #1206 added another example plugin (log as dockWidget) --- .../src/plugins/CMakeLists.txt | 1 + .../src/plugins/log/CMakeLists.txt | 36 +++++ .../src/plugins/log/log_form.ui | 56 +++++++ .../src/plugins/log/log_plugin.cpp | 144 ++++++++++++++++++ .../src/plugins/log/log_plugin.h | 85 +++++++++++ .../src/plugins/log/qt_displayer.cpp | 127 +++++++++++++++ .../src/plugins/log/qt_displayer.h | 55 +++++++ 7 files changed, 504 insertions(+) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/log/CMakeLists.txt create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_form.ui create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt index f3a4da658..b8112e446 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/CMakeLists.txt @@ -1 +1,2 @@ ADD_SUBDIRECTORY(example) +ADD_SUBDIRECTORY(log) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/CMakeLists.txt new file mode 100644 index 000000000..7b8b85d5d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/CMakeLists.txt @@ -0,0 +1,36 @@ +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_SOURCE_DIR} + ${LIBXML2_INCLUDE_DIR} + ${QT_INCLUDES}) + +FILE(GLOB SRC *.cpp *.h) +SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_manager.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin_spec.h) + +SET(OVQT_PLUG_LOG_HDR log_plugin.h) +SET(OVQT_PLUG_LOG_UIS log_form.ui) + +SET(QT_USE_QTGUI TRUE) +SET(QT_USE_QTOPENGL TRUE) + +QT4_WRAP_CPP(OVQT_PLUG_LOG_MOC_SRC ${OVQT_PLUG_LOG_HDR}) +QT4_WRAP_UI( OVQT_PLUG_LOG_UI_HDRS ${OVQT_PLUG_LOG_UIS} ) + +SOURCE_GROUP(QtResources FILES ${OVQT_PLUG_LOG_UIS}) +SOURCE_GROUP(QtGeneratedUiHdr FILES ${OVQT_PLUG_LOG_UI_HDRS}) +SOURCE_GROUP(QtGeneratedMocSrc FILES ${OVQT_PLUG_LOG_MOC_SRC}) +SOURCE_GROUP("Log Plugin" FILES ${SRC}) +SOURCE_GROUP("OVQT Extension System" FILES ${OVQT_EXT_SYS_SRC}) + +ADD_LIBRARY(ovqt_plugin_log SHARED ${SRC} ${OVQT_PLUG_LOG_MOC_SRC} ${OVQT_EXT_SYS_SRC} ${OVQT_PLUG_LOG_UI_HDRS}) + +TARGET_LINK_LIBRARIES(ovqt_plugin_log nelmisc ${QT_LIBRARIES}) + +NL_DEFAULT_PROPS(ovqt_plugin_log "NeL, Tools, 3D: Object Viewer Qt Plugin: Log") +NL_ADD_RUNTIME_FLAGS(ovqt_plugin_log) +NL_ADD_LIB_SUFFIX(ovqt_plugin_log) + +ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} -DQT_PLUGIN -DQT_SHARED ${QT_DEFINITIONS}) + +INSTALL(TARGETS ovqt_plugin_log LIBRARY DESTINATION lib RUNTIME DESTINATION bin ARCHIVE DESTINATION lib COMPONENT tools3d) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_form.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_form.ui new file mode 100644 index 000000000..5d018c741 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_form.ui @@ -0,0 +1,56 @@ + + + CLogPlugin + + + + 0 + 0 + 540 + 370 + + + + + 0 + 0 + + + + + 89 + 111 + + + + + 524287 + 524287 + + + + Log + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp new file mode 100644 index 000000000..26c40435c --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.cpp @@ -0,0 +1,144 @@ +/* +Log Plugin Qt +Copyright (C) 2010 Adrian Jaekel + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#include "log_plugin.h" + +// Qt includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// NeL includes +#include + +// Project includes +#include "../../extension_system/iplugin_spec.h" +#include "qt_displayer.h" + +using namespace Plugin; + +CLogPlugin::CLogPlugin(QWidget *parent): QDockWidget(parent) +{ + _ui.setupUi(this); +} + +CLogPlugin::~CLogPlugin() +{ + NLMISC::ErrorLog->removeDisplayer(_displayer); + NLMISC::WarningLog->removeDisplayer(_displayer); + NLMISC::DebugLog->removeDisplayer(_displayer); + NLMISC::AssertLog->removeDisplayer(_displayer); + NLMISC::InfoLog->removeDisplayer(_displayer); + delete _displayer; +} + +bool CLogPlugin::initialize(NLQT::IPluginManager *pluginManager, QString *errorString) +{ + Q_UNUSED(errorString); + _plugMan = pluginManager; + QString str; + + QList listPlug = pluginManager->plugins(); + + Q_FOREACH (NLQT::IPluginSpec *plugSpec, listPlug) + str += plugSpec->name(); + + nlinfo(str.toStdString().c_str()); + + return true; +} + +void CLogPlugin::extensionsInitialized() +{ + QMenu *helpMenu = qobject_cast(objectByName("ovqt.Menu.Help")); + helpMenu->addSeparator(); + QAction *newAction = helpMenu->addAction("LogPlugin"); + + connect(newAction, SIGNAL(triggered()), this, SLOT(createLogDock())); +} + +void CLogPlugin::createLogDock() +{ + NLMISC::ErrorLog->addDisplayer(_displayer); + NLMISC::WarningLog->addDisplayer(_displayer); + NLMISC::DebugLog->addDisplayer(_displayer); + NLMISC::AssertLog->addDisplayer(_displayer); + NLMISC::InfoLog->addDisplayer(_displayer); + + QMainWindow *wnd = qobject_cast(objectByName("CMainWindow")); + + // create log dock widget + wnd->addDockWidget(Qt::RightDockWidgetArea, this); + + +} + +void CLogPlugin::setNelContext(NLMISC::INelContext *nelContext) +{ + nlassert(!NLMISC::INelContext::isContextInitialised()); + _LibContext = static_cast(nelContext); + + _displayer = new NLQT::CQtDisplayer(_ui.plainTextEdit); + +} + +QString CLogPlugin::name() const +{ + return "LogPlugin"; +} + +QString CLogPlugin::version() const +{ + return "0.1"; +} + +QString CLogPlugin::vendor() const +{ + return "aquiles"; +} + +QString CLogPlugin::description() const +{ + return "DockWidget to display all log messages from NeL."; +} + +QObject* CLogPlugin::objectByName(const QString &name) const +{ + Q_FOREACH (QObject *qobj, _plugMan->allObjects()) + if (qobj->objectName() == name) + return qobj; + return 0; +} + +NLQT::IPluginSpec *CLogPlugin::pluginByName(const QString &name) const +{ + Q_FOREACH (NLQT::IPluginSpec *spec, _plugMan->plugins()) + if (spec->name() == name) + return spec; + return 0; +} + +Q_EXPORT_PLUGIN(CLogPlugin) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.h new file mode 100644 index 000000000..5b9cf962e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/log_plugin.h @@ -0,0 +1,85 @@ +/* +Log Plugin Qt +Copyright (C) 2010 Adrian Jaekel + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +#ifndef LOG_PLUGIN_H +#define LOG_PLUGIN_H + +#include "../../extension_system/iplugin.h" + +#include "nel/misc/app_context.h" + +// Qt includes +#include + +// Project includes +#include "ui_log_form.h" + +namespace NLMISC +{ + class CLibraryContext; +} + +namespace NLQT +{ + class IPluginSpec; + class CQtDisplayer; +} + +namespace Plugin +{ + + class CLogPlugin : public QDockWidget, public NLQT::IPlugin + { + Q_OBJECT + Q_INTERFACES(NLQT::IPlugin) + public: + CLogPlugin(QWidget *parent = 0); + ~CLogPlugin(); + + bool initialize(NLQT::IPluginManager *pluginManager, QString *errorString); + void extensionsInitialized(); + + void setNelContext(NLMISC::INelContext *nelContext); + + QString name() const; + QString version() const; + QString vendor() const; + QString description() const; + + QObject *objectByName(const QString &name) const; + NLQT::IPluginSpec *pluginByName(const QString &name) const; + + private Q_SLOTS: + void createLogDock(); + + protected: + NLMISC::CLibraryContext *_LibContext; + + private: + NLQT::IPluginManager *_plugMan; + + Ui::CLogPlugin _ui; + + NLQT::CQtDisplayer *_displayer; + + }; + +} // namespace Plugin + +#endif // LOG_PLUGIN_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.cpp new file mode 100644 index 000000000..aaeae9a1a --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.cpp @@ -0,0 +1,127 @@ +/* +Georges Editor Qt +Copyright (C) 2010 Adrian Jaekel + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + +// Nel includes + +#include "qt_displayer.h" +#include +#include + +namespace NLQT +{ + + CQtDisplayer::CQtDisplayer(QPlainTextEdit *dlgDebug, bool eraseLastLog, + const char *displayerName, bool raw) + : NLMISC::IDisplayer (displayerName), _NeedHeader(true), _LastLogSizeChecked(0), _Raw(raw) + { + setParam(dlgDebug,eraseLastLog); + } + + CQtDisplayer::CQtDisplayer() + : IDisplayer (""), _NeedHeader(true), _LastLogSizeChecked(0), _Raw(false) + { + ; + } + + CQtDisplayer::~CQtDisplayer() { + ; + } + + void CQtDisplayer::setParam (QPlainTextEdit *dlgDebug, bool eraseLastLog) + { + m_DlgDebug=dlgDebug; + //dlgDebug->dlgDbgText->WriteText("test"); + } + + void CQtDisplayer::doDisplay ( const NLMISC::CLog::TDisplayInfo& args, const char *message ) + { + bool needSpace = false; + std::string str; + + if(m_DlgDebug==NULL) + return; + + QTextCharFormat format; + + if (args.Date != 0 && !_Raw) { + str += dateToHumanString(args.Date); + needSpace = true; + } + + if (args.LogType != NLMISC::CLog::LOG_NO && !_Raw) + { + if (needSpace) { str += " "; needSpace = false; } + str += logTypeToString(args.LogType); + if (args.LogType == NLMISC::CLog::LOG_WARNING) + format.setForeground(QBrush(QColor("red"))); + else + format.setForeground(QBrush(QColor("black"))); + needSpace = true; + } + + // Write thread identifier + /*if ( args.ThreadId != 0 && !_Raw) { + if (needSpace) { str += " "; needSpace = false; } + str += NLMISC::toString(args.ThreadId); + needSpace = true; + }*/ + /*if (!args.ProcessName.empty() && !_Raw) { + if (needSpace) { str += " "; needSpace = false; } + str += args.ProcessName; + needSpace = true; + }*/ + + //if (args.FileName != NULL && !_Raw) { + // if (needSpace) { str += " "; needSpace = false; } + // str += NLMISC::CFile::getFilename(args.FileName); + // needSpace = true; + //} + + /*if (args.Line != -1 && !_Raw) { + if (needSpace) { str += " "; needSpace = false; } + str += NLMISC::toString(args.Line); + needSpace = true; + }*/ + + if (args.FuncName != NULL && !_Raw) + { + if (needSpace) + { + str += " "; needSpace = false; + } + str += args.FuncName; + needSpace = true; + } + + if (needSpace) + { + str += " : "; needSpace = false; + } + str += message; + + + + m_DlgDebug->textCursor().insertText(str.c_str(), format); + //m_DlgDebug->setCenterOnScroll(true); + m_DlgDebug->centerCursor(); + //m_DlgDebug->ensureCursorVisible(); + + } + +} \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.h new file mode 100644 index 000000000..e73bf6937 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/log/qt_displayer.h @@ -0,0 +1,55 @@ +/* +Georges Editor Qt +Copyright (C) 2010 Adrian Jaekel + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +*/ + + +#ifndef QTDISPLAYER_H +#define QTDISPLAYER_H + +// NeL includes +#include + +// Qt includes +#include + +namespace NLQT +{ + + class CQtDisplayer : virtual public NLMISC::IDisplayer + { + + public: + CQtDisplayer(QPlainTextEdit *dlgDebug, bool eraseLastLog = false, + const char *displayerName = "", bool raw = false); + CQtDisplayer(); + ~CQtDisplayer (); + void setParam (QPlainTextEdit *dlgDebug, bool eraseLastLog = false); + + protected: + virtual void doDisplay ( const NLMISC::CLog::TDisplayInfo& args, const char *message ); + + private: + QPlainTextEdit *m_DlgDebug; + bool _NeedHeader; + uint _LastLogSizeChecked; + bool _Raw; + };/* class CQtDisplayer */ + +} /* namespace Plugin */ + +#endif //QTDISPLAYER_H \ No newline at end of file