mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-11 17:59:03 +00:00
Changed: #1206 added another example plugin (log as dockWidget)
This commit is contained in:
parent
31b8ed8eb0
commit
819dd477d3
7 changed files with 504 additions and 0 deletions
|
@ -1 +1,2 @@
|
|||
ADD_SUBDIRECTORY(example)
|
||||
ADD_SUBDIRECTORY(log)
|
||||
|
|
|
@ -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)
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CLogPlugin</class>
|
||||
<widget class="QDockWidget" name="CLogPlugin">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>540</width>
|
||||
<height>370</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>89</width>
|
||||
<height>111</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>524287</width>
|
||||
<height>524287</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Log</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
Log Plugin Qt
|
||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#include "log_plugin.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QtCore/QObject>
|
||||
#include <QtGui/QMessageBox>
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QMenuBar>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QFile>
|
||||
#include <QDateTime>
|
||||
#include <QTextStream>
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/debug.h>
|
||||
|
||||
// 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<NLQT::IPluginSpec *> 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<QMenu *>(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<QMainWindow *>(objectByName("CMainWindow"));
|
||||
|
||||
// create log dock widget
|
||||
wnd->addDockWidget(Qt::RightDockWidgetArea, this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CLogPlugin::setNelContext(NLMISC::INelContext *nelContext)
|
||||
{
|
||||
nlassert(!NLMISC::INelContext::isContextInitialised());
|
||||
_LibContext = static_cast<NLMISC::CLibraryContext *>(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)
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
Log Plugin Qt
|
||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef LOG_PLUGIN_H
|
||||
#define LOG_PLUGIN_H
|
||||
|
||||
#include "../../extension_system/iplugin.h"
|
||||
|
||||
#include "nel/misc/app_context.h"
|
||||
|
||||
// Qt includes
|
||||
#include <QDockWidget>
|
||||
|
||||
// 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
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
Georges Editor Qt
|
||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
// Nel includes
|
||||
|
||||
#include "qt_displayer.h"
|
||||
#include <nel/misc/common.h>
|
||||
#include <nel/misc/file.h>
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
Georges Editor Qt
|
||||
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QTDISPLAYER_H
|
||||
#define QTDISPLAYER_H
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/displayer.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
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
|
Loading…
Reference in a new issue