forked from xiaozai511/LuaMemorySnapShot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsefiledialog.cpp
More file actions
141 lines (120 loc) · 3.89 KB
/
parsefiledialog.cpp
File metadata and controls
141 lines (120 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "parsefiledialog.h"
#include "ui_parsefiledialog.h"
#include "memoryrefrenceinfo.h"
#include "common.h"
#include "refrencetreedock.h"
#include <QMessageBox>
#include <QTimer>
#include <QFileInfo>
//ParseFileDialog::ParseFileDialog(QWidget *parent) :
// QDialog(parent),
// ui(new Ui::ParseFileDialog),
// bCompare(false),
// m_infoMgr(nullptr)
//{
// ui->setupUi(this);
//}
ParseFileDialog::ParseFileDialog(const QString& filePath, MemoryRefrenceInfoMgr* infoMgr, QWidget *parent) :
QDialog(parent),
ui(new Ui::ParseFileDialog)
{
ui->setupUi(this);
Q_ASSERT(dynamic_cast<RefrenceTreeDock*>(parent));
bCompare = false;
m_infoMgr = infoMgr;
m_filePath = filePath;
m_infoMgrBase = nullptr;
bAllOver = false;
//register
connect(m_infoMgr, SIGNAL(parseRunning(QString,int,int)), SLOT(onParseRunning(QString,int,int)));
connect(m_infoMgr, SIGNAL(parseFinished(QString)), SLOT(onParseFinished()));
onBaseParseFinished();
}
ParseFileDialog::ParseFileDialog(const QString& before, const QString& after, MemoryRefrenceInfoMgr* infoMgr, QWidget *parent) :
QDialog(parent),
ui(new Ui::ParseFileDialog)
{
ui->setupUi(this);
bCompare = true;
m_infoMgr = infoMgr;
m_filePath = after;
m_filePathBase = before;
bAllOver = false;
m_infoMgrBase = new MemoryRefrenceInfoMgr;
//register
connect(m_infoMgr, SIGNAL(parseRunning(QString,int,int)), SLOT(onParseRunning(QString,int,int)));
connect(m_infoMgr, SIGNAL(parseFinished(QString)), SLOT(onParseFinished()));
connect(m_infoMgrBase, SIGNAL(parseRunning(QString,int,int)), SLOT(onParseRunning(QString,int,int)));
connect(m_infoMgrBase, SIGNAL(parseFinished(QString)), SLOT(onBaseParseFinished()));
ui->noticeText->setText(tr("解析文件:") + QFileInfo(m_filePathBase).fileName());
m_infoMgrBase->parsFile(m_filePathBase);
}
ParseFileDialog::~ParseFileDialog()
{
delete ui;
stopParsing();
SAFE_DELETE(m_infoMgrBase);
}
void ParseFileDialog::onParseRunning(const QString& filepath, int usetime, int progress)
{
// qDebug() << "onParseRunning" << filepath << usetime << progress;
Q_UNUSED(filepath);
static QString strUseTime(tr("已用时间:"));
ui->noticeTime->setText(strUseTime + QString::asprintf("%0.2f(s)", (float)usetime / 1000));
ui->progressBar->setValue(progress);
}
void ParseFileDialog::onBaseParseFinished()
{
if(!m_infoMgr || m_filePath.length() == 0) {
onParseFinished();
return;
}
ui->noticeText->setText(tr("解析文件:") + QFileInfo(m_filePath).fileName());
m_infoMgr->parsFile(m_filePath, m_infoMgrBase);
}
void ParseFileDialog::onParseFinished()
{
// ui->progressBar->setValue(100);
// QTimer::singleShot(100, this, "close");
ui->noticeText->setText(tr("文件解析完成,等待更新列表!"));
ui->noticeText->repaint();
RefrenceTreeDock* parentDock = (RefrenceTreeDock*)parent();
QString title("RefrenceTree");
if(bCompare) {
title.append(QString("-Compared: %1 - %2").arg(QFileInfo(m_filePathBase).fileName(),
QFileInfo(m_filePath).fileName()));
} else {
title.append(QString("-File: %1").arg(QFileInfo(m_filePath).fileName()));
}
parentDock->updateTreeView(title);
bAllOver = true;
this->close();
}
void ParseFileDialog::closeEvent(QCloseEvent* event)
{
if(bAllOver) {
event->accept();
} else {
auto ret = QMessageBox::question(this, "Notice",
tr("文件解析中,是否需要取消?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if(ret == QMessageBox::Yes) {
stopParsing();
event->accept();
} else {
event->ignore();
}
}
}
//停止正在执行的线程
void ParseFileDialog::stopParsing()
{
if(m_infoMgr && m_infoMgr->isRunning()) {
m_infoMgr->setRunning(false);
m_infoMgr->wait();
}
if(m_infoMgrBase && m_infoMgrBase->isRunning()) {
m_infoMgrBase->setRunning(false);
m_infoMgrBase->wait();
}
}