-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtqmakewatchermaindialog.cpp
102 lines (91 loc) · 2.61 KB
/
qtqmakewatchermaindialog.cpp
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
#include "qtqmakewatchermaindialog.h"
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
#include <QDesktopWidget>
#include <QFile>
#include "fileio.h"
#include "ui_qtqmakewatchermaindialog.h"
ribi::QtQmakeWatcherMainDialog::QtQmakeWatcherMainDialog(QWidget *parent)
: QtHideAndShowDialog(parent),
ui(new Ui::QtQmakeWatcherMainDialog)
{
ui->setupUi(this);
ui->edit_pro->setWordWrapMode(QTextOption::NoWrap);
ui->edit_makefile->setWordWrapMode(QTextOption::NoWrap);
ui->edit_diff->setWordWrapMode(QTextOption::NoWrap);
QObject::connect(ui->button_qmake,&QPushButton::clicked,
this,&ribi::QtQmakeWatcherMainDialog::OnQmake
);
//Put the dialog in the screen center
const QRect screen = QApplication::desktop()->screenGeometry();
this->setGeometry(0,0,screen.width() * 8 / 10,screen.height() * 8 / 10);
this->move( screen.center() - this->rect().center() );
}
ribi::QtQmakeWatcherMainDialog::~QtQmakeWatcherMainDialog() noexcept
{
delete ui;
}
void ribi::QtQmakeWatcherMainDialog::OnQmake()
{
//Save text to file
{
const std::string s = ui->edit_pro->document()->toPlainText().toStdString();
std::ofstream f("tmp.pro");
f << s << '\n';
}
//Execute commands
{
const bool has_error = std::system("cp Makefile oldmake");
assert(!has_error);
if (has_error) throw std::runtime_error("'cp Makefile oldmake' failed");
}
{
const bool has_error = std::system("qmake tmp.pro");
assert(!has_error);
if (has_error) throw std::runtime_error("'qmake tmp.pro' failed");
}
bool has_diff = true;
{
const bool has_error = std::system("diff Makefile oldmake > tmp.txt");
if (has_error) has_diff = false;
}
//Display Makefile
{
ui->edit_makefile->clear();
const std::vector<std::string> v(ribi::fileio::FileIo().FileToVector("Makefile"));
for(const std::string& s: v)
{
ui->edit_makefile->appendPlainText(QString(s.c_str()));
}
}
//Display diff
ui->edit_diff->setPlainText("No diff");
if (has_diff)
{
ui->edit_diff->clear();
const std::vector<std::string> v(ribi::fileio::FileIo().FileToVector("tmp.txt"));
for(const std::string& s: v)
{
std::string t = s;
if (!s.empty() && s[0] == '>')
{
//Old
t = "<font color=#0000FF><"
+ s.substr(1,s.size()-1)
+ "</font>";
}
if (!s.empty() && s[0] == '<')
{
//New
t = "<b><font color=#FF0000>>"
+ s.substr(1,s.size()-1)
+ "</font></b>";
}
ui->edit_diff->appendHtml(QString(t.c_str()));
}
}
}