Skip to content

Commit

Permalink
Merge pull request #1467 from zenustech/zeno2-fixbug
Browse files Browse the repository at this point in the history
merge log from optix thread.
  • Loading branch information
zhouhang95 authored Oct 13, 2023
2 parents 7e746d7 + d53ec55 commit 116c969
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ui/zenoedit/res/stylesheet/qlineedit.qss
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ QPlainTextEdit[cssClass="logpanel"]
color: #A3B1C0;
background-color: rgb(24,29,33);
border: 1px solid rgb(18,20,22);
font-weight: 500;
font-family:'Arial' 9pt;
}

QLineEdit[cssClass = "blackboard_title"]
Expand Down
32 changes: 32 additions & 0 deletions ui/zenoedit/zenoapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ ZenoApplication::ZenoApplication(int &argc, char **argv)
m_errSteam.registerMsgHandler();
verifyVersion();

//register optix log proxy
bool ret = connect(m_errSteam.optixLogProxy().get(), SIGNAL(optixlogReady(const QString&)), this, SLOT(onOptixlogReady(const QString&)), Qt::QueuedConnection);

QStringList locations;
locations = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
#ifdef Q_OS_WIN
Expand All @@ -39,6 +42,35 @@ ZenoApplication::~ZenoApplication()
{
}

void ZenoApplication::onOptixlogReady(const QString& msg)
{
if (msg.startsWith("["))
{
QMessageLogger logger("zeno", 0, 0);
QChar tip = msg.at(1);

auto& mgr = GraphsManagment::instance();
if (tip == 'T') {
mgr.appendLog(QtDebugMsg, "zeno", 0, msg);
}
else if (tip == 'D') {
mgr.appendLog(QtDebugMsg, "zeno", 0, msg);
}
else if (tip == 'I') {
mgr.appendLog(QtInfoMsg, "zeno", 0, msg);
}
else if (tip == 'C') {
mgr.appendLog(QtCriticalMsg, "zeno", 0, msg);
}
else if (tip == 'W') {
mgr.appendLog(QtWarningMsg, "zeno", 0, msg);
}
else if (tip == 'E') {
mgr.appendLog(QtFatalMsg, "zeno", 0, msg);
}
}
}

QString ZenoApplication::readQss(const QString& qssPath)
{
bool ret = false;
Expand Down
3 changes: 3 additions & 0 deletions ui/zenoedit/zenoapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class ZenoApplication : public QApplication
#endif
QStandardItemModel* logModel() const;

private slots:
void onOptixlogReady(const QString& msg);

private:
QString readQss(const QString& qssPath);
void initMetaTypes();
Expand Down
7 changes: 7 additions & 0 deletions ui/zenoedit/zwidgetostream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ZWidgetErrStream::ZWidgetErrStream(std::ostream &stream)
, m_stream(stream)
{
m_old_buf = m_stream.rdbuf();
m_spProxyOptixLog = std::make_shared<ProxySendOptixLog>();
m_stream.rdbuf(this);
}

Expand All @@ -18,6 +19,11 @@ ZWidgetErrStream::~ZWidgetErrStream()
m_stream.rdbuf(m_old_buf);
}

std::shared_ptr<ProxySendOptixLog> ZWidgetErrStream::optixLogProxy() const
{
return m_spProxyOptixLog;
}

bool ZWidgetErrStream::isGUIThread()
{
//return true;
Expand All @@ -27,6 +33,7 @@ bool ZWidgetErrStream::isGUIThread()
std::streamsize ZWidgetErrStream::xsputn(const char* p, std::streamsize n)
{
if (!isGUIThread()) {
emit m_spProxyOptixLog->optixlogReady(QString::fromUtf8(p, n));
return _base::xsputn(p, n);
}

Expand Down
14 changes: 14 additions & 0 deletions ui/zenoedit/zwidgetostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
#include <QString>
#include <string>

class ProxySendOptixLog : public QObject
{
Q_OBJECT
public:
ProxySendOptixLog() {}

signals:
void optixlogReady(const QString& msg);
};


class ZWidgetErrStream : public std::basic_streambuf<char>
{
typedef std::basic_streambuf<char> _base;
Expand All @@ -14,6 +25,7 @@ class ZWidgetErrStream : public std::basic_streambuf<char>
virtual ~ZWidgetErrStream();
static void registerMsgHandler();
static void appendFormatMsg(std::string const& str);
std::shared_ptr<ProxySendOptixLog> optixLogProxy() const;

protected:
virtual std::streamsize xsputn(const char* p, std::streamsize n) override;
Expand All @@ -29,6 +41,8 @@ class ZWidgetErrStream : public std::basic_streambuf<char>
std::ostream &m_stream;
std::streambuf *m_old_buf;
std::string m_linebuffer;

std::shared_ptr<ProxySendOptixLog> m_spProxyOptixLog;
};

#endif

0 comments on commit 116c969

Please sign in to comment.