Files
gcs-nf/App/ToolsUI/tools_Index1/tools_Index1.cpp
T
2022-02-10 14:26:23 +08:00

158 lines
3.2 KiB
C++

#include "tools_Index1.h"
#include "ui_tools_Index1.h"
Tools_Index1::Tools_Index1(QWidget *parent) :
QWidget(parent),
ui(new Ui::Tools_Index1)
{
ui->setupUi(this);
m_parent = parent;
//load qss
QFile file(":/qss/Setting.qss");
file.open(QFile::ReadOnly);
QTextStream filetext(&file);
QString stylesheet = filetext.readAll();
this->setStyleSheet(stylesheet);
file.close();
QDateTime current = QDateTime::currentDateTime();
log_file_name = QString("./log/textlog/%1.log").arg(current.toString("yyyyMMddHHmmss"));
log_file = new QFile(log_file_name);
if(log_file->open(QIODevice::WriteOnly | QIODevice::Text))
{
}
StringModel = new QStringListModel(ui->listView);
ui->listView->setModel(StringModel);
ui->listView->scrollToBottom();
//ui->listView->setAlternatingRowColors();
//setLog(tr("uav ground control system"));
}
Tools_Index1::~Tools_Index1()
{
if(log_file)
{
log_file->close();
}
delete ui;
}
void Tools_Index1::closeEvent(QCloseEvent *event)
{
setFloat();
event->ignore();
}
void Tools_Index1::setFloat(void)
{
if(this->parent())
{
this->setParent(nullptr);
this->move(50,50);
this->resize(800,480);
this->show();
}
else
{
this->setParent(m_parent);
this->setGeometry(m_parent->geometry());
this->move(0,0);
//this->hide();
this->show();
this->resize(m_parent->size());
}
}
void Tools_Index1::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event)
//scope->setGeometry(ui->frame->geometry());
update();
}
void Tools_Index1::setLog(const QString &message)
{
QString time = QDateTime::currentDateTime().toString("hh:mm:ss.zzz");
static int count = 0;
QStringList slist = StringModel->stringList();
slist.append(tr("[%1] %2 >> %3").arg(QString::number(count)).arg(time).arg(message));
StringModel->setStringList(slist);
ui->listView->scrollToBottom();
count ++;
//if(log_file->open(QIODevice::WriteOnly | QIODevice::Text) )
//{
if(log_file)
{
if(log_file->isOpen())
{
QString s;
s.append(tr("[%1] %2 >> %3\n").arg(QString::number(count)).arg(time).arg(message));
QTextStream out(log_file);
out << s;
log_file->flush();
}
}
}
void Tools_Index1::on_pushButton_ExportLog_clicked()
{
if(StringModel->stringList().size() > 0)
{
QFileDialog *dlg = new QFileDialog();
QString fileName = dlg->getSaveFileName(this, tr("Selete Path of File..."),
log_file_name,
tr("log file (*.log)"));
if(!fileName.isEmpty())
{
log_file = new QFile(fileName);
if(log_file->open(QIODevice::WriteOnly))
{
QStringList l = StringModel->stringList();
QDataStream data(log_file);
foreach (QString s, l) {
s.append("\r\n");
log_file->write(s.toUtf8());
}
log_file->close();
}
}
}
else
{
//emit sho
}
}