X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=gui%2Fmainwindow.cpp;h=591c557e55567eda81a93c1341eadf7cc727aa7a;hb=77ff98a6bc65e7ddf29e241e6b40e5ac63337871;hp=a5fbaccc5eabf6b667f60e59c8f5933858707c90;hpb=b39e1c64410931066aa8d648fa9c765121a6ea42;p=apitrace diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index a5fbacc..591c557 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -18,14 +18,15 @@ #include "vertexdatainterpreter.h" #include +#include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -36,7 +37,8 @@ MainWindow::MainWindow() : QMainWindow(), m_selectedEvent(0), - m_stateEvent(0) + m_stateEvent(0), + m_nonDefaultsLookupEvent(0) { m_ui.setupUi(this); initObjects(); @@ -73,9 +75,9 @@ void MainWindow::openTrace() QDir::homePath(), tr("Trace Files (*.trace)")); - qDebug()<< "File name : " <setValue(0); newTraceFile(fileName); } @@ -104,7 +104,7 @@ void MainWindow::callItemSelected(const QModelIndex &index) QByteArray data = call->arguments()[call->binaryDataIndex()].toByteArray(); m_vdataInterpreter->setData(data); - QVariantList args = call->arguments(); + QVector args = call->arguments(); for (int i = 0; i < call->argNames().count(); ++i) { QString name = call->argNames()[i]; @@ -132,7 +132,7 @@ void MainWindow::callItemSelected(const QModelIndex &index) m_ui.detailsDock->hide(); m_ui.vertexDataDock->hide(); } - if (m_selectedEvent && !m_selectedEvent->state().isEmpty()) { + if (m_selectedEvent && m_selectedEvent->hasState()) { fillStateForFrame(); } else m_ui.stateDock->hide(); @@ -154,14 +154,14 @@ void MainWindow::replayStart() dlgUi.doubleBufferingCB->setChecked( m_retracer->isDoubleBuffered()); - dlgUi.benchmarkCB->setChecked( - m_retracer->isBenchmarking()); + dlgUi.errorCheckCB->setChecked( + !m_retracer->isBenchmarking()); if (dlg.exec() == QDialog::Accepted) { m_retracer->setDoubleBuffered( dlgUi.doubleBufferingCB->isChecked()); m_retracer->setBenchmarking( - dlgUi.benchmarkCB->isChecked()); + !dlgUi.errorCheckCB->isChecked()); replayTrace(false); } } @@ -176,6 +176,9 @@ void MainWindow::replayStop() void MainWindow::newTraceFile(const QString &fileName) { + qDebug()<< "Loading : " <setValue(0); m_trace->setFileName(fileName); if (fileName.isEmpty()) { @@ -202,6 +205,11 @@ void MainWindow::replayFinished(const QString &output) statusBar()->showMessage(output); } m_stateEvent = 0; + m_ui.actionShowErrorsDock->setEnabled(m_trace->hasErrors()); + m_ui.errorsDock->setVisible(m_trace->hasErrors()); + if (!m_trace->hasErrors()) + m_ui.errorsTreeWidget->clear(); + statusBar()->showMessage( tr("Replaying finished!"), 2000); } @@ -212,6 +220,7 @@ void MainWindow::replayError(const QString &message) m_ui.actionReplay->setEnabled(true); m_ui.actionLookupState->setEnabled(true); m_stateEvent = 0; + m_nonDefaultsLookupEvent = 0; m_progressBar->hide(); statusBar()->showMessage( @@ -254,12 +263,12 @@ void MainWindow::replayTrace(bool dumpState) } else if (m_selectedEvent->type() == ApiTraceEvent::Frame) { ApiTraceFrame *frame = static_cast(m_selectedEvent); - if (frame->calls.isEmpty()) { + if (frame->isEmpty()) { //XXX i guess we could still get the current state qDebug()<<"tried to get a state for an empty frame"; return; } - index = frame->calls.first()->index(); + index = frame->calls().first()->index(); } else { qDebug()<<"Unknown event type"; return; @@ -300,13 +309,18 @@ void MainWindow::lookupState() MainWindow::~MainWindow() { + delete m_trace; + m_trace = 0; + + delete m_proxyModel; + delete m_model; } static void variantToString(const QVariant &var, QString &str) { if (var.type() == QVariant::List) { - QVariantList lst = var.toList(); + QVector lst = var.toList().toVector(); str += QLatin1String("["); for (int i = 0; i < lst.count(); ++i) { QVariant val = lst[i]; @@ -344,7 +358,8 @@ variantMapToItems(const QVariantMap &map, const QVariantMap &defaultMap, QList &items) +variantListToItems(const QVector &lst, const QVector &defaultLst, + QList &items) { for (int i = 0; i < lst.count(); ++i) { QString key = QString::number(i); @@ -366,7 +381,7 @@ static bool isVariantDeep(const QVariant &var) { if (var.type() == QVariant::List) { - QVariantList lst = var.toList(); + QVector lst = var.toList().toVector(); for (int i = 0; i < lst.count(); ++i) { if (isVariantDeep(lst[i])) { return true; @@ -412,8 +427,8 @@ variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVa variantMapToItems(map, defaultMap, children); } if (var.type() == QVariant::List) { - QVariantList lst = var.toList(); - QVariantList defaultLst = defaultVar.toList(); + QVector lst = var.toList().toVector(); + QVector defaultLst = defaultVar.toList().toVector(); variantListToItems(lst, defaultLst, children); } item->addChildren(children); @@ -422,13 +437,43 @@ variantToItem(const QString &key, const QVariant &var, const QVariant &defaultVa return item; } -void MainWindow::fillStateForFrame() +static void addSurfaceItem(const ApiSurface &surface, + const QString &label, + QTreeWidgetItem *parent, + QTreeWidget *tree) { - QVariantMap params; + int width = surface.size().width(); + int height = surface.size().height(); + QIcon icon(QPixmap::fromImage(surface.thumb())); + QTreeWidgetItem *item = new QTreeWidgetItem(parent); + + item->setIcon(0, icon); + + QString descr = + QString::fromLatin1("%1, %2 x %3") + .arg(label) + .arg(width) + .arg(height); + + //item->setText(1, descr); + QLabel *l = new QLabel(descr, tree); + l->setWordWrap(true); + tree->setItemWidget(item, 1, l); + + item->setData(0, Qt::UserRole, surface.image()); +} - if (!m_selectedEvent || m_selectedEvent->state().isEmpty()) +void MainWindow::fillStateForFrame() +{ + if (!m_selectedEvent || !m_selectedEvent->hasState()) return; + if (m_nonDefaultsLookupEvent) { + m_ui.nonDefaultsCB->blockSignals(true); + m_ui.nonDefaultsCB->setChecked(true); + m_ui.nonDefaultsCB->blockSignals(false); + } + bool nonDefaults = m_ui.nonDefaultsCB->isChecked(); QVariantMap defaultParams; if (nonDefaults) { @@ -436,11 +481,10 @@ void MainWindow::fillStateForFrame() defaultParams = defaultState.parameters(); } - const ApiTraceState &state = m_selectedEvent->state(); + const ApiTraceState &state = *m_selectedEvent->state(); m_ui.stateTreeWidget->clear(); - params = state.parameters(); QList items; - variantMapToItems(params, defaultParams, items); + variantMapToItems(state.parameters(), defaultParams, items); m_ui.stateTreeWidget->insertTopLevelItems(0, items); QMap shaderSources = state.shaderSources(); @@ -450,6 +494,11 @@ void MainWindow::fillStateForFrame() m_sourcesWidget->setShaders(shaderSources); } + m_ui.uniformsTreeWidget->clear(); + QList uniformsItems; + variantMapToItems(state.uniforms(), QVariantMap(), uniformsItems); + m_ui.uniformsTreeWidget->insertTopLevelItems(0, uniformsItems); + const QList &textures = state.textures(); const QList &fbos = @@ -470,20 +519,9 @@ void MainWindow::fillStateForFrame() for (int i = 0; i < textures.count(); ++i) { const ApiTexture &texture = textures[i]; - QIcon icon(QPixmap::fromImage(texture.thumb())); - QTreeWidgetItem *item = new QTreeWidgetItem(textureItem); - item->setIcon(0, icon); - int width = texture.size().width(); - int height = texture.size().height(); - QString descr = - QString::fromLatin1("%1, %2 x %3") - .arg(texture.target()) - .arg(width) - .arg(height); - item->setText(1, descr); - - item->setData(0, Qt::UserRole, - texture.image()); + addSurfaceItem(texture, texture.label(), + textureItem, + m_ui.surfacesTreeWidget); } } if (!fbos.isEmpty()) { @@ -496,20 +534,9 @@ void MainWindow::fillStateForFrame() for (int i = 0; i < fbos.count(); ++i) { const ApiFramebuffer &fbo = fbos[i]; - QIcon icon(QPixmap::fromImage(fbo.thumb())); - QTreeWidgetItem *item = new QTreeWidgetItem(fboItem); - item->setIcon(0, icon); - int width = fbo.size().width(); - int height = fbo.size().height(); - QString descr = - QString::fromLatin1("%1, %2 x %3") - .arg(fbo.type()) - .arg(width) - .arg(height); - item->setText(1, descr); - - item->setData(0, Qt::UserRole, - fbo.image()); + addSurfaceItem(fbo, fbo.type(), + fboItem, + m_ui.surfacesTreeWidget); } } m_ui.surfacesTab->setEnabled(true); @@ -538,12 +565,17 @@ void MainWindow::showSurfacesMenu(const QPoint &pos) return; QMenu menu(tr("Surfaces"), this); - //add needed actions + QAction *act = menu.addAction(tr("View Image")); act->setStatusTip(tr("View the currently selected surface")); connect(act, SIGNAL(triggered()), SLOT(showSelectedSurface())); + act = menu.addAction(tr("Save Image")); + act->setStatusTip(tr("Save the currently selected surface")); + connect(act, SIGNAL(triggered()), + SLOT(saveSelectedSurface())); + menu.exec(tree->viewport()->mapToGlobal(pos)); } @@ -556,15 +588,32 @@ void MainWindow::showSelectedSurface() return; QVariant var = item->data(0, Qt::UserRole); - m_imageViewer->setImage(var.value()); - m_imageViewer->show(); - m_imageViewer->raise(); - m_imageViewer->activateWindow(); + QImage img = var.value(); + ImageViewer *viewer = new ImageViewer(this); + + QString title; + if (currentCall()) { + title = tr("QApiTrace - Surface at %1 (%2)") + .arg(currentCall()->name()) + .arg(currentCall()->index()); + } else { + title = tr("QApiTrace - Surface Viewer"); + } + viewer->setWindowTitle(title); + viewer->setAttribute(Qt::WA_DeleteOnClose, true); + viewer->setImage(img); + QRect screenRect = QApplication::desktop()->availableGeometry(); + viewer->resize(qMin(int(0.75 * screenRect.width()), img.width()) + 40, + qMin(int(0.75 * screenRect.height()), img.height()) + 40); + viewer->show(); + viewer->raise(); + viewer->activateWindow(); } void MainWindow::initObjects() { m_ui.stateTreeWidget->sortByColumn(0, Qt::AscendingOrder); + m_ui.uniformsTreeWidget->sortByColumn(0, Qt::AscendingOrder); m_sourcesWidget = new ShadersSourceWidget(m_ui.shadersTab); QVBoxLayout *layout = new QVBoxLayout; @@ -585,14 +634,13 @@ void MainWindow::initObjects() m_vdataInterpreter->setTypeFromString( m_ui.vertexTypeCB->currentText()); - m_imageViewer = new ImageViewer(this); - m_model = new ApiTraceModel(); m_model->setApiTrace(m_trace); m_proxyModel = new ApiTraceFilter(); m_proxyModel->setSourceModel(m_model); m_ui.callView->setModel(m_proxyModel); - m_ui.callView->setItemDelegate(new ApiCallDelegate); + m_ui.callView->setItemDelegate( + new ApiCallDelegate(m_ui.callView)); m_ui.callView->resizeColumnToContents(0); m_ui.callView->header()->swapSections(0, 1); m_ui.callView->setColumnWidth(1, 42); @@ -628,11 +676,6 @@ void MainWindow::initObjects() m_searchWidget->hide(); m_traceProcess = new TraceProcess(this); - - new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G), - this, SLOT(slotGoTo())); - new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F), - this, SLOT(slotSearch())); } void MainWindow::initConnections() @@ -652,8 +695,8 @@ void MainWindow::initConnections() this, SLOT(replayFinished(const QString&))); connect(m_retracer, SIGNAL(error(const QString&)), this, SLOT(replayError(const QString&))); - connect(m_retracer, SIGNAL(foundState(const ApiTraceState&)), - this, SLOT(replayStateFound(const ApiTraceState&))); + connect(m_retracer, SIGNAL(foundState(ApiTraceState*)), + this, SLOT(replayStateFound(ApiTraceState*))); connect(m_retracer, SIGNAL(retraceErrors(const QList&)), this, SLOT(slotRetraceErrors(const QList&))); @@ -726,17 +769,27 @@ void MainWindow::initConnections() SLOT(createdTrace(const QString&))); connect(m_traceProcess, SIGNAL(error(const QString&)), SLOT(traceError(const QString&))); + + connect(m_ui.errorsDock, SIGNAL(visibilityChanged(bool)), + m_ui.actionShowErrorsDock, SLOT(setChecked(bool))); + connect(m_ui.actionShowErrorsDock, SIGNAL(triggered(bool)), + m_ui.errorsDock, SLOT(setVisible(bool))); + connect(m_ui.errorsTreeWidget, + SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), + this, SLOT(slotErrorSelected(QTreeWidgetItem*))); } -void MainWindow::replayStateFound(const ApiTraceState &state) +void MainWindow::replayStateFound(ApiTraceState *state) { m_stateEvent->setState(state); m_model->stateSetOnEvent(m_stateEvent); - if (m_selectedEvent == m_stateEvent) { + if (m_selectedEvent == m_stateEvent || + m_nonDefaultsLookupEvent == m_selectedEvent) { fillStateForFrame(); } else { m_ui.stateDock->hide(); } + m_nonDefaultsLookupEvent = 0; } void MainWindow::slotGoTo() @@ -773,7 +826,8 @@ void MainWindow::slotSearch() m_searchWidget->show(); } -void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity) +void MainWindow::slotSearchNext(const QString &str, + Qt::CaseSensitivity sensitivity) { QModelIndex index = m_ui.callView->currentIndex(); ApiTraceEvent *event = 0; @@ -796,24 +850,24 @@ void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitiv else { Q_ASSERT(event->type() == ApiTraceCall::Frame); ApiTraceFrame *frame = static_cast(event); - call = frame->calls.value(0); + call = frame->call(0); } if (!call) { m_searchWidget->setFound(false); return; } - const QList &calls = m_trace->calls(); + const QVector &calls = m_trace->calls(); int callNum = calls.indexOf(call); for (int i = callNum + 1; i < calls.count(); ++i) { ApiTraceCall *testCall = calls[i]; - QString txt = testCall->filterText(); - if (txt.contains(str, sensitivity)) { - QModelIndex index = m_proxyModel->indexForCall(testCall); - /* if it's not valid it means that the proxy model has already - * filtered it out */ - if (index.isValid()) { + QModelIndex index = m_proxyModel->indexForCall(testCall); + /* if it's not valid it means that the proxy model has already + * filtered it out */ + if (index.isValid()) { + QString txt = testCall->searchText(); + if (txt.contains(str, sensitivity)) { m_ui.callView->setCurrentIndex(index); m_searchWidget->setFound(true); return; @@ -823,7 +877,8 @@ void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitiv m_searchWidget->setFound(false); } -void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity) +void MainWindow::slotSearchPrev(const QString &str, + Qt::CaseSensitivity sensitivity) { QModelIndex index = m_ui.callView->currentIndex(); ApiTraceEvent *event = 0; @@ -846,24 +901,24 @@ void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitiv else { Q_ASSERT(event->type() == ApiTraceCall::Frame); ApiTraceFrame *frame = static_cast(event); - call = frame->calls.value(0); + call = frame->call(0); } if (!call) { m_searchWidget->setFound(false); return; } - const QList &calls = m_trace->calls(); + const QVector &calls = m_trace->calls(); int callNum = calls.indexOf(call); for (int i = callNum - 1; i >= 0; --i) { ApiTraceCall *testCall = calls[i]; - QString txt = testCall->filterText(); - if (txt.contains(str, sensitivity)) { - QModelIndex index = m_proxyModel->indexForCall(testCall); - /* if it's not valid it means that the proxy model has already - * filtered it out */ - if (index.isValid()) { + QModelIndex index = m_proxyModel->indexForCall(testCall); + /* if it's not valid it means that the proxy model has already + * filtered it out */ + if (index.isValid()) { + QString txt = testCall->searchText(); + if (txt.contains(str, sensitivity)) { m_ui.callView->setCurrentIndex(index); m_searchWidget->setFound(true); return; @@ -881,22 +936,12 @@ void MainWindow::fillState(bool nonDefaults) m_ui.nonDefaultsCB->blockSignals(true); m_ui.nonDefaultsCB->setChecked(false); m_ui.nonDefaultsCB->blockSignals(false); - int ret = QMessageBox::question( - this, tr("Empty Default State"), - tr("The applcation needs to figure out the " - "default state for the current trace. " - "This only has to be done once and " - "afterwards you will be able to enable " - "displaying of non default state for all calls." - "\nDo you want to lookup the default state now?"), - QMessageBox::Yes | QMessageBox::No); - if (ret != QMessageBox::Yes) - return; ApiTraceFrame *firstFrame = m_trace->frameAt(0); ApiTraceEvent *oldSelected = m_selectedEvent; if (!firstFrame) return; + m_nonDefaultsLookupEvent = m_selectedEvent; m_selectedEvent = firstFrame; lookupState(); m_selectedEvent = oldSelected; @@ -916,12 +961,14 @@ void MainWindow::customContextMenuRequested(QPoint pos) ApiTraceEvent *event = index.data(ApiTraceModel::EventRole).value(); - if (!event || event->type() != ApiTraceEvent::Call) + if (!event) return; menu.addAction(QIcon(":/resources/media-record.png"), tr("Lookup state"), this, SLOT(lookupState())); - menu.addAction(tr("Edit"), this, SLOT(editCall())); + if (event->type() == ApiTraceEvent::Call) { + menu.addAction(tr("Edit"), this, SLOT(editCall())); + } menu.exec(QCursor::pos()); } @@ -952,14 +999,15 @@ void MainWindow::slotSaved() void MainWindow::slotGoFrameStart() { ApiTraceFrame *frame = currentFrame(); - if (!frame || frame->calls.isEmpty()) { + if (!frame || frame->isEmpty()) { return; } - QList::const_iterator itr; + QVector::const_iterator itr; + QVector calls = frame->calls(); - itr = frame->calls.constBegin(); - while (itr != frame->calls.constEnd()) { + itr = calls.constBegin(); + while (itr != calls.constEnd()) { ApiTraceCall *call = *itr; QModelIndex idx = m_proxyModel->indexForCall(call); if (idx.isValid()) { @@ -973,12 +1021,13 @@ void MainWindow::slotGoFrameStart() void MainWindow::slotGoFrameEnd() { ApiTraceFrame *frame = currentFrame(); - if (!frame || frame->calls.isEmpty()) { + if (!frame || frame->isEmpty()) { return; } - QList::const_iterator itr; + QVector::const_iterator itr; + QVector calls = frame->calls(); - itr = frame->calls.constEnd(); + itr = calls.constEnd(); do { --itr; ApiTraceCall *call = *itr; @@ -987,7 +1036,7 @@ void MainWindow::slotGoFrameEnd() m_ui.callView->setCurrentIndex(idx); break; } - } while (itr != frame->calls.constBegin()); + } while (itr != calls.constBegin()); } ApiTraceFrame * MainWindow::currentFrame() const @@ -1031,8 +1080,83 @@ void MainWindow::slotRetraceErrors(const QList &errors) item->setData(1, Qt::DisplayRole, type); item->setData(2, Qt::DisplayRole, error.message); } +} + +void MainWindow::slotErrorSelected(QTreeWidgetItem *current) +{ + if (current) { + ApiTraceCall *call = + current->data(0, Qt::UserRole).value(); + Q_ASSERT(call); + QModelIndex index = m_proxyModel->indexForCall(call); + if (index.isValid()) { + m_ui.callView->setCurrentIndex(index); + } else { + statusBar()->showMessage(tr("Call has been filtered out.")); + } + } +} + +ApiTraceCall * MainWindow::currentCall() const +{ + if (m_selectedEvent && + m_selectedEvent->type() == ApiTraceEvent::Call) { + return static_cast(m_selectedEvent); + } + return NULL; +} + +void MainWindow::saveSelectedSurface() +{ + QTreeWidgetItem *item = + m_ui.surfacesTreeWidget->currentItem(); + + if (!item || !m_trace) + return; + + QVariant var = item->data(0, Qt::UserRole); + QImage img = var.value(); + + QString imageIndex; + if (currentCall()) { + imageIndex = tr("_call_%1") + .arg(currentCall()->index()); + } else if (currentFrame()) { + ApiTraceCall *firstCall = currentFrame()->call(0); + if (firstCall) { + imageIndex = tr("_frame_%1") + .arg(firstCall->index()); + } else { + qDebug()<<"unknown frame number"; + imageIndex = tr("_frame_%1") + .arg(firstCall->index()); + } + } - m_ui.errorsDock->setVisible(!errors.isEmpty()); + //which of the surfaces are we saving + QTreeWidgetItem *parent = item->parent(); + int parentIndex = + m_ui.surfacesTreeWidget->indexOfTopLevelItem(parent); + if (parentIndex < 0) { + parentIndex = 0; + } + int childIndex = 0; + if (parent) { + childIndex = parent->indexOfChild(item); + } else { + childIndex = m_ui.surfacesTreeWidget->indexOfTopLevelItem(item); + } + + + QString fileName = + tr("%1%2-%3_%4.png") + .arg(m_trace->fileName()) + .arg(imageIndex) + .arg(parentIndex) + .arg(childIndex); + //qDebug()<<"save "<showMessage( tr("Saved '%1'").arg(fileName), 5000); } #include "mainwindow.moc"