Implement state diffing.
authorZack Rusin <zack@kde.org>
Wed, 13 Apr 2011 05:35:03 +0000 (01:35 -0400)
committerZack Rusin <zack@kde.org>
Wed, 13 Apr 2011 05:35:03 +0000 (01:35 -0400)
Makes it possible to show only the parts of the state which differ
from the defaults. very neat

gui/apitrace.cpp
gui/apitrace.h
gui/mainwindow.cpp
gui/mainwindow.h
gui/ui/mainwindow.ui

index 03ff02e..592202f 100644 (file)
@@ -181,4 +181,13 @@ ApiTraceCall * ApiTrace::callWithIndex(int idx) const
     return NULL;
 }
 
+ApiTraceState ApiTrace::defaultState() const
+{
+    ApiTraceFrame *frame = frameAt(0);
+    if (!frame)
+        return ApiTraceState();
+
+    return frame->state();
+}
+
 #include "apitrace.moc"
index f1f6811..2bf916a 100644 (file)
@@ -29,6 +29,8 @@ public:
 
     FrameMarker frameMarker() const;
 
+    ApiTraceState defaultState() const;
+
     QList<ApiTraceCall*> calls() const;
     ApiTraceCall *callAt(int idx) const;
     ApiTraceCall *callWithIndex(int idx) const;
index f57ccc8..8269bfd 100644 (file)
@@ -315,6 +315,10 @@ void MainWindow::fillStateForFrame()
     if (!m_selectedEvent || m_selectedEvent->state().isEmpty())
         return;
 
+    bool nonDefaults = m_ui.nonDefaultsCB->isChecked();
+    ApiTraceState defaultState = m_trace->defaultState();
+    QVariantMap defaultParams = defaultState.parameters();
+
     const ApiTraceState &state = m_selectedEvent->state();
     m_ui.stateTreeWidget->clear();
     params = state.parameters();
@@ -324,6 +328,12 @@ void MainWindow::fillStateForFrame()
         QString val;
 
         variantToString(itr.value(), val);
+        if (nonDefaults) {
+            QString defaultValue;
+            variantToString(defaultParams[key], defaultValue);
+            if (defaultValue == val)
+                continue;
+        }
         //qDebug()<<"key = "<<key;
         //qDebug()<<"val = "<<val;
         QStringList lst;
@@ -575,12 +585,17 @@ void MainWindow::initConnections()
     connect(m_ui.detailsWebView, SIGNAL(linkClicked(const QUrl&)),
             this, SLOT(openHelp(const QUrl&)));
 
+    connect(m_ui.nonDefaultsCB, SIGNAL(toggled(bool)),
+            this, SLOT(fillState(bool)));
+
     connect(m_jumpWidget, SIGNAL(jumpTo(int)),
             SLOT(slotJumpTo(int)));
 
-    connect(m_searchWidget, SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
+    connect(m_searchWidget,
+            SIGNAL(searchNext(const QString&, Qt::CaseSensitivity)),
             SLOT(slotSearchNext(const QString&, Qt::CaseSensitivity)));
-    connect(m_searchWidget, SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
+    connect(m_searchWidget,
+            SIGNAL(searchPrev(const QString&, Qt::CaseSensitivity)),
             SLOT(slotSearchPrev(const QString&, Qt::CaseSensitivity)));
 
     connect(m_traceProcess, SIGNAL(tracedFile(const QString&)),
@@ -734,4 +749,36 @@ void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitiv
     m_searchWidget->setFound(false);
 }
 
+void MainWindow::fillState(bool nonDefaults)
+{
+    if (nonDefaults) {
+        ApiTraceState defaultState = m_trace->defaultState();
+        if (defaultState.isEmpty()) {
+            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_selectedEvent = firstFrame;
+            lookupState();
+            m_selectedEvent = oldSelected;
+        }
+    }
+    fillStateForFrame();
+}
+
 #include "mainwindow.moc"
index 73e3084..de413c0 100644 (file)
@@ -56,6 +56,7 @@ private slots:
     void slotSearch();
     void slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity);
     void slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity);
+    void fillState(bool nonDefaults);
 
 private:
     void initObjects();
index 09c164c..c0c6237 100644 (file)
      <item>
       <widget class="QTabWidget" name="stateTabWidget">
        <property name="currentIndex">
-        <number>2</number>
+        <number>0</number>
        </property>
        <widget class="QWidget" name="parametersTab">
         <attribute name="title">
         </attribute>
         <layout class="QVBoxLayout" name="verticalLayout_3">
          <item>
+          <widget class="QCheckBox" name="nonDefaultsCB">
+           <property name="text">
+            <string>Only show non-defaults</string>
+           </property>
+          </widget>
+         </item>
+         <item>
           <widget class="QTreeWidget" name="stateTreeWidget">
            <property name="editTriggers">
             <set>QAbstractItemView::NoEditTriggers</set>