]> git.cworth.org Git - apitrace/blobdiff - gui/mainwindow.cpp
Plugging some memory leaks
[apitrace] / gui / mainwindow.cpp
index 90e5f2a92262e3e6df7f5bbdb608fb775512bdf5..1b4de12b6f35c2c7094334b266e73af1d8e22ea4 100644 (file)
 #include "vertexdatainterpreter.h"
 
 #include <QAction>
+#include <QApplication>
 #include <QDebug>
 #include <QDesktopServices>
+#include <QDesktopWidget>
 #include <QDir>
 #include <QFileDialog>
 #include <QLineEdit>
@@ -304,6 +306,11 @@ void MainWindow::lookupState()
 
 MainWindow::~MainWindow()
 {
+    delete m_trace;
+    m_trace = 0;
+
+    delete m_proxyModel;
+    delete m_model;
 }
 
 static void
@@ -560,10 +567,23 @@ void MainWindow::showSelectedSurface()
         return;
 
     QVariant var = item->data(0, Qt::UserRole);
-
+    QImage img = var.value<QImage>();
     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(var.value<QImage>());
+    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();
@@ -780,7 +800,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;
@@ -815,12 +836,12 @@ void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitiv
 
     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->filterText();
+            if (txt.contains(str, sensitivity)) {
                 m_ui.callView->setCurrentIndex(index);
                 m_searchWidget->setFound(true);
                 return;
@@ -830,7 +851,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;
@@ -865,12 +887,12 @@ void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitiv
 
     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->filterText();
+            if (txt.contains(str, sensitivity)) {
                 m_ui.callView->setCurrentIndex(index);
                 m_searchWidget->setFound(true);
                 return;
@@ -1055,4 +1077,13 @@ void MainWindow::slotErrorSelected(QTreeWidgetItem *current)
     }
 }
 
+ApiTraceCall * MainWindow::currentCall() const
+{
+    if (m_selectedEvent &&
+        m_selectedEvent->type() == ApiTraceEvent::Call) {
+        return static_cast<ApiTraceCall*>(m_selectedEvent);
+    }
+    return NULL;
+}
+
 #include "mainwindow.moc"