1 #include "mainwindow.h"
3 #include "apitracecall.h"
4 #include "apicalldelegate.h"
5 #include "apitracemodel.h"
6 #include "apitracefilter.h"
11 #include <QFileDialog>
13 #include <QMessageBox>
19 MainWindow::MainWindow()
25 m_model = new ApiTraceModel();
26 m_proxyModel = new ApiTraceFilter();
27 m_proxyModel->setSourceModel(m_model);
28 m_ui.callView->setModel(m_proxyModel);
29 m_ui.callView->setItemDelegate(new ApiCallDelegate);
30 for (int column = 0; column < m_model->columnCount(); ++column)
31 m_ui.callView->resizeColumnToContents(column);
33 QToolBar *toolBar = addToolBar(tr("Navigation"));
34 m_filterEdit = new QLineEdit(toolBar);
35 toolBar->addWidget(m_filterEdit);
37 m_ui.detailsDock->hide();
39 connect(m_ui.actionOpen, SIGNAL(triggered()),
40 this, SLOT(openTrace()));
41 connect(m_ui.actionQuit, SIGNAL(triggered()),
44 connect(m_ui.actionReplay, SIGNAL(triggered()),
45 this, SLOT(replayStart()));
46 connect(m_ui.actionStop, SIGNAL(triggered()),
47 this, SLOT(replayStop()));
49 connect(m_ui.callView, SIGNAL(activated(const QModelIndex &)),
50 this, SLOT(callItemSelected(const QModelIndex &)));
51 connect(m_filterEdit, SIGNAL(returnPressed()),
52 this, SLOT(filterTrace()));
55 void MainWindow::openTrace()
58 QFileDialog::getOpenFileName(
62 tr("Trace Files (*.trace)"));
64 qDebug()<< "File name : " <<fileName;
66 newTraceFile(fileName);
67 m_model->loadTraceFile(fileName);
70 void MainWindow::loadTrace(const QString &fileName)
72 if (!QFile::exists(fileName)) {
73 QMessageBox::warning(this, tr("File Missing"),
74 tr("File '%1' doesn't exist.").arg(fileName));
77 qDebug()<< "Loading : " <<fileName;
79 m_model->loadTraceFile(fileName);
80 newTraceFile(fileName);
83 void MainWindow::callItemSelected(const QModelIndex &index)
85 ApiTraceCall *call = index.data().value<ApiTraceCall*>();
87 m_ui.detailsWebView->setHtml(call->toHtml());
88 m_ui.detailsDock->show();
90 m_ui.detailsDock->hide();
94 void MainWindow::filterTrace()
96 m_proxyModel->setFilterString(m_filterEdit->text());
99 void MainWindow::replayStart()
101 if (!m_replayProcess) {
103 QString format = QLatin1String("%1;");
105 QString format = QLatin1String("%1:");
107 QString buildPath = format.arg(BUILD_DIR);
108 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
109 env.insert("PATH", buildPath + env.value("PATH"));
111 qputenv("PATH", env.value("PATH").toLatin1());
113 m_replayProcess = new QProcess(this);
114 m_replayProcess->setProcessEnvironment(env);
116 connect(m_replayProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
117 this, SLOT(replayFinished()));
118 connect(m_replayProcess, SIGNAL(error(QProcess::ProcessError)),
119 this, SLOT(replayError(QProcess::ProcessError)));
122 if (m_traceFileName.isEmpty())
125 QStringList arguments;
126 arguments << m_traceFileName;
128 m_replayProcess->start(QLatin1String("glretrace"),
131 m_ui.actionStop->setEnabled(true);
132 m_ui.actionReplay->setEnabled(false);
135 void MainWindow::replayStop()
137 if (m_replayProcess) {
138 m_replayProcess->kill();
140 m_ui.actionStop->setEnabled(false);
141 m_ui.actionReplay->setEnabled(true);
145 void MainWindow::newTraceFile(const QString &fileName)
147 m_traceFileName = fileName;
149 if (m_traceFileName.isEmpty()) {
150 m_ui.actionReplay->setEnabled(false);
152 m_ui.actionReplay->setEnabled(true);
156 void MainWindow::replayFinished()
158 m_ui.actionStop->setEnabled(false);
159 m_ui.actionReplay->setEnabled(true);
161 QString output = m_replayProcess->readAllStandardOutput();
164 qDebug()<<"Process finished = ";
165 qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
166 qDebug()<<"\tout = "<<output;
169 if (output.length() < 80) {
170 statusBar()->showMessage(output);
174 void MainWindow::replayError(QProcess::ProcessError err)
176 m_ui.actionStop->setEnabled(false);
177 m_ui.actionReplay->setEnabled(true);
179 qDebug()<<"Process error = "<<err;
180 qDebug()<<"\terr = "<<m_replayProcess->readAllStandardError();
181 qDebug()<<"\tout = "<<m_replayProcess->readAllStandardOutput();
182 QMessageBox::warning(
183 this, tr("Replay Failed"),
184 tr("Couldn't execute the replay file '%1'").arg(m_traceFileName));
187 #include "mainwindow.moc"