PeriDyno 1.2.1
Loading...
Searching...
No Matches
WLogWidget.cpp
Go to the documentation of this file.
1#include "WLogWidget.h"
2
3#include <cstdio>
4#include <Wt/WPushButton.h>
5
7
15
20
22{
24 WLogMessage::instance->updateLog(m.text.c_str());
25 }
26}
27
28void WLogMessage::updateLog(const char* text)
29{
30 message = message + text + "\n";
31 m_signal.emit(message);
32}
33
34
35Wt::Signal<std::string>& WLogMessage::updateText()
36{
37 return m_signal;
38}
39
41 : mParent(parent)
42{
43 this->setLayoutSizeAware(true);
44 //this->setOverflow(Wt::Overflow::Auto);
45 this->setMargin(10);
46
47 text = this->addNew<Wt::WTextArea>();
48 //text->setHeight(Wt::WLength("95%"));
49 text->resize("95%", "95%");
50 text->setStyleClass("save-middle");
51
52 auto downloadButton = this->addWidget(std::make_unique< Wt::WPushButton>("Update"));
53 downloadButton->setMargin(10, Wt::Side::Top);
54 downloadButton->setStyleClass("btn-primary");
55
56 downloadButton->clicked().connect([=]
57 {
58 auto mScene = parent->getScene();
59 std::ostringstream oss;
60 oss << mScene;
61 std::string filePath = oss.str() + ".txt";
62 std::string content;
63
64 std::ifstream fileStream(filePath);
65 if (!fileStream.is_open()) {
66 std::cerr << "Unable to open file for reading." << std::endl;
67 return 1;
68 }
69
70 std::getline(fileStream, content, '\0'); // 读取整个文件内容
71 fileStream.close();
72
73 text->setText(content);
74
75 if (std::remove(filePath.c_str()) == 0) {
76 std::cout << "File successfully deleted." << std::endl;
77 }
78 else {
79 std::cerr << "Error deleting file." << std::endl;
80 }
81
82 });
83}
84
86
87void WLogWidget::showMessage(std::string s)
88{
89 text->setText("123");
90}
static WLogMessage * instance
Definition WLogWidget.h:25
Wt::Signal< std::string > m_signal
Definition WLogWidget.h:34
void updateLog(const char *text)
static void RecieveLogMessage(const dyno::Log::Message &m)
Wt::Signal< std::string > & updateText()
std::string message
Definition WLogWidget.h:29
void showMessage(std::string s)
WMainWindow * mParent
Definition WLogWidget.h:49
Wt::WTextArea * text
Definition WLogWidget.h:48
WLogWidget(WMainWindow *parent)
std::shared_ptr< dyno::SceneGraph > getScene()
static void setUserReceiver(void(*userFunc)(const Message &))
Set user function to receive newly sent messages to logger.
Definition Log.cpp:57
std::string text
Definition Log.h:56