]> git.cworth.org Git - apitrace/commitdiff
Large chunk of functionality to show errors.
authorZack Rusin <zack@kde.org>
Tue, 19 Apr 2011 05:33:58 +0000 (01:33 -0400)
committerZack Rusin <zack@kde.org>
Tue, 19 Apr 2011 05:33:58 +0000 (01:33 -0400)
12 files changed:
gui/apicalldelegate.cpp
gui/apicalldelegate.h
gui/apitrace.cpp
gui/apitrace.h
gui/apitracecall.cpp
gui/apitracecall.h
gui/apitracemodel.cpp
gui/mainwindow.cpp
gui/qapitrace.qrc
gui/resources/script-error.png [new file with mode: 0644]
gui/saverthread.cpp
gui/ui/mainwindow.ui

index c2a1b23f54f47172fcc59885989011b2c68c7d58..800fcddb1cc842ae95cf0bc69870bc15345a3578 100644 (file)
@@ -12,7 +12,8 @@
 ApiCallDelegate::ApiCallDelegate(QWidget *parent)
     : QStyledItemDelegate(parent),
       m_stateEmblem(":/resources/dialog-information.png"),
-      m_editEmblem(":/resources/document-edit.png")
+      m_editEmblem(":/resources/document-edit.png"),
+      m_errorEmblem(":/resources/script-error.png")
 {
 }
 
@@ -40,6 +41,12 @@ void ApiCallDelegate::paint(QPainter *painter,
         }
         if (event->type() == ApiTraceEvent::Call) {
             ApiTraceCall *call = static_cast<ApiTraceCall*>(event);
+            if (call->hasError()) {
+                QPixmap px = m_errorEmblem.pixmap(option.rect.height(),
+                                                  option.rect.height());
+                painter->drawPixmap(option.rect.topLeft() + offset, px);
+                offset += QPoint(option.rect.height() + 5, 0);
+            }
             if (call->edited()) {
                 QPixmap px = m_editEmblem.pixmap(option.rect.height(),
                                                  option.rect.height());
index 55cd13ef2b13b7fd2617f55899d27956b2541391..18c8b33ac519d56367b1340686dc9208307f4816 100644 (file)
@@ -18,6 +18,7 @@ public:
 private:
     QIcon m_stateEmblem;
     QIcon m_editEmblem;
+    QIcon m_errorEmblem;
 };
 
 #endif
index 4ce4cd423f64873c87abb4477855ec86419c0dcd..6fa994a5d43d1ff3fdda929368bada341e43bdf2 100644 (file)
@@ -260,4 +260,9 @@ bool ApiTrace::isSaving() const
     return m_saver->isRunning();
 }
 
+void ApiTrace::callError(ApiTraceCall *call)
+{
+    emit changed(call);
+}
+
 #include "apitrace.moc"
index 32e24084b26802545fb1dbe800d788239df5231f..a493fd2eb1e23beea9ef62b68c9b234747130887 100644 (file)
@@ -45,6 +45,7 @@ public:
 
     void callEdited(ApiTraceCall *call);
     void callReverted(ApiTraceCall *call);
+    void callError(ApiTraceCall *call);
 
     bool edited() const;
     bool needsSaving() const;
index b2ded2ff053fdfc2b110f9d3ecd7cab70102fc4a..bac3d73762ce1575902e3f4ce351045c3a6f0aa9 100644 (file)
@@ -8,6 +8,38 @@
 #define QT_USE_FAST_OPERATOR_PLUS
 #include <QStringBuilder>
 
+const char * const styleSheet =
+    ".call {\n"
+    "    font-weight:bold;\n"
+    // text shadow looks great but doesn't work well in qtwebkit 4.7
+    "    /*text-shadow: 0px 2px 3px #555;*/\n"
+    "    font-size: 1.2em;\n"
+    "}\n"
+    ".arg-name {\n"
+    "    border: 1px solid rgb(238,206,0);\n"
+    "    border-radius: 4px;\n"
+    "    background: yellow;\n"
+    "    padding: 2px;\n"
+    "    box-shadow: 0px 1px 3px dimgrey;\n"
+    "    -webkit-transition: background 1s linear;\n"
+    "}\n"
+    ".arg-name:hover {\n"
+    "    background: white;\n"
+    "}\n"
+    ".arg-value {\n"
+    "    color: #0000ff;\n"
+    "}\n"
+    ".error {\n"
+    "    margin: 10px;\n"
+    "    padding: 0;\n"
+    "    color: red;\n"
+    "    background: #6fb2e5;\n"
+    "    box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
+    "    -o-box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
+    "    -webkit-box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
+    "    -moz-box-shadow: 0 1px 5px #0061aa, inset 0 10px 20px #b6f9ff;\n"
+    "}\n";
+
 ApiPointer::ApiPointer(unsigned long long val)
     : m_value(val)
 {
@@ -316,14 +348,16 @@ QString ApiTraceCall::toHtml() const
     if (!m_richText.isEmpty())
         return m_richText;
 
+    m_richText = QLatin1String("<div class=\"call\">");
+
     if (m_helpUrl.isEmpty()) {
-        m_richText = QString::fromLatin1(
-            "%1) <span style=\"font-weight:bold\">%2</span>(")
-                     .arg(m_index)
-                     .arg(m_name);
+        m_richText += QString::fromLatin1(
+            "%1) <span class=\"callName\">%2</span>(")
+                      .arg(m_index)
+                      .arg(m_name);
     } else {
-        m_richText = QString::fromLatin1(
-            "%1) <span style=\"font-weight:bold\"><a href=\"%2\">%3</a></span>(")
+        m_richText += QString::fromLatin1(
+            "%1) <span class=\"callName\"><a href=\"%2\">%3</a></span>(")
                       .arg(m_index)
                       .arg(m_helpUrl.toString())
                       .arg(m_name);
@@ -331,11 +365,14 @@ QString ApiTraceCall::toHtml() const
 
     QVariantList argValues = arguments();
     for (int i = 0; i < m_argNames.count(); ++i) {
-        m_richText += m_argNames[i] +
-                      QLatin1Literal(" = ") +
-                      QLatin1Literal("<span style=\"color:#0000ff\">") +
-                      apiVariantToString(argValues[i]) +
-                      QLatin1Literal("</span>");
+        m_richText +=
+            QLatin1String("<span class=\"arg-name\">") +
+            m_argNames[i] +
+            QLatin1String("</span>") +
+            QLatin1Literal(" = ") +
+            QLatin1Literal("<span class=\"arg-value\">") +
+            apiVariantToString(argValues[i]) +
+            QLatin1Literal("</span>");
         if (i < m_argNames.count() - 1)
             m_richText += QLatin1String(", ");
     }
@@ -348,7 +385,17 @@ QString ApiTraceCall::toHtml() const
             apiVariantToString(m_returnValue) +
             QLatin1String("</span>");
     }
+    m_richText += QLatin1String("</div>");
+
+    m_richText =
+        QString::fromLatin1(
+            "<html><head><style type=\"text/css\" media=\"all\">"
+            "%1</style></head><body>%2</body></html>")
+        .arg(styleSheet)
+        .arg(m_richText);
     m_richText.squeeze();
+
+    //qDebug()<<m_richText;
     return m_richText;
 }
 
@@ -678,9 +725,7 @@ QVariantList ApiTraceCall::originalValues() const
 
 void ApiTraceCall::setEditedValues(const QVariantList &lst)
 {
-    ApiTrace *trace = 0;
-    if (m_parentFrame)
-        trace = m_parentFrame->parentTrace();
+    ApiTrace *trace = parentTrace();
 
     m_editedValues = lst;
     //lets regenerate data
@@ -754,3 +799,30 @@ unsigned long long ApiPointer::value() const
     return m_value;
 }
 
+bool ApiTraceCall::hasError() const
+{
+    return !m_error.isEmpty();
+}
+
+QString ApiTraceCall::error() const
+{
+    return m_error;
+}
+
+void ApiTraceCall::setError(const QString &msg)
+{
+    if (m_error != msg) {
+        ApiTrace *trace = parentTrace();
+        m_error = msg;
+        if (trace)
+            trace->callError(this);
+    }
+}
+
+ApiTrace * ApiTraceCall::parentTrace() const
+{
+    if (m_parentFrame)
+        return m_parentFrame->parentTrace();
+    return NULL;
+}
+
index 59c6fe75eec5613025e895033097defd93f423b9..3afd2abb7f275f75ffc098c212d4754487ec8075 100644 (file)
@@ -195,6 +195,10 @@ public:
     ApiTraceFrame *parentFrame()const;
     void setParentFrame(ApiTraceFrame *frame);
 
+    bool hasError() const;
+    QString error() const;
+    void setError(const QString &msg);
+
     QVariantList originalValues() const;
 
     bool edited() const;
@@ -202,6 +206,8 @@ public:
     QVariantList editedValues() const;
     void revert();
 
+    ApiTrace *parentTrace() const;
+
     QString toHtml() const;
     QString filterText() const;
     QStaticText staticText() const;
@@ -219,6 +225,8 @@ private:
 
     QVariantList m_editedValues;
 
+    QString m_error;
+
     mutable QString m_richText;
     mutable QString m_filterText;
     mutable bool m_hasBinaryData;
index a39a92935dfba6812ab5f13512dce25535b53f1e..70d292adaa04d5af549e98a1aeffe641360a5adc 100644 (file)
@@ -282,16 +282,17 @@ void ApiTraceModel::callChanged(ApiTraceCall *call)
 {
     ApiTrace *trace = call->parentFrame()->parentTrace();
 
-    Q_ASSERT(trace);
-    trace->save();
-
-#if 0
+#if 1
     qDebug()<<"Call changed = "<<call->edited();
     qDebug()<<"\ttrace edited = "<<trace->edited();
     qDebug()<<"\ttrace file = "<<trace->fileName();
     qDebug()<<"\ttrace needs saving = "<<trace->needsSaving();
 #endif
 
+    Q_ASSERT(trace);
+    if (trace->needsSaving())
+        trace->save();
+
     ApiTraceFrame *frame = call->parentFrame();
     int row = frame->calls.indexOf(call);
     QModelIndex index = createIndex(row, 0, call);
index f40a1441f61eed895f1e7ba1a40af7e118684380..1af5af03120eb850e3e365840b9c80e1876ddc63 100644 (file)
@@ -606,11 +606,13 @@ void MainWindow::initObjects()
     m_argsEditor = new ArgumentsEditor(this);
 
     m_ui.detailsDock->hide();
+    m_ui.errorsDock->hide();
     m_ui.vertexDataDock->hide();
     m_ui.stateDock->hide();
     setDockOptions(dockOptions() | QMainWindow::ForceTabbedDocks);
 
     tabifyDockWidget(m_ui.stateDock, m_ui.vertexDataDock);
+    tabifyDockWidget(m_ui.detailsDock, m_ui.errorsDock);
 
     m_ui.surfacesTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
 
@@ -725,6 +727,10 @@ void MainWindow::initConnections()
 void MainWindow::replayStateFound(const ApiTraceState &state)
 {
     m_stateEvent->setState(state);
+    if (m_stateEvent->type() == ApiTraceEvent::Call) {
+        ApiTraceCall *call = static_cast<ApiTraceCall*>(m_stateEvent);
+        call->setError(tr("Some wonky error."));
+    }
     m_model->stateSetOnEvent(m_stateEvent);
     if (m_selectedEvent == m_stateEvent) {
         fillStateForFrame();
index 4d8223f058af16d3fb027d2e9b89c66c61b7de1c..fe002f1b432e9c4d7152812b09a704821996376d 100644 (file)
@@ -17,6 +17,7 @@
     <file>resources/media-playback-start.png</file>
     <file>resources/media-playback-stop.png</file>
     <file>resources/media-record.png</file>
+    <file>resources/script-error.png</file>
     <file>resources/glreference.tsv</file>
 </qresource>
 </RCC>
diff --git a/gui/resources/script-error.png b/gui/resources/script-error.png
new file mode 100644 (file)
index 0000000..c7ace70
Binary files /dev/null and b/gui/resources/script-error.png differ
index ac726a1d8c32ae2551d551666a7a4ead8ead09e1..b7e3ebcbc3481a34f84e228aeb956ceb331e5acd 100644 (file)
@@ -221,7 +221,7 @@ void SaverThread::run()
 {
     qputenv("TRACE_PATH", m_fileName.toLocal8Bit());
     unsigned id = 0;
-
+    qDebug()<<"saver thread!";
     Trace::Open();
     for (int i = 0; i < m_calls.count(); ++i) {
         ApiTraceCall *call = m_calls[i];
index 76c391e59d536969a33f7dc9e89bc7303b5ecbaf..3f15da25e1673fc8c3c4deb3a77f8fae06240bad 100644 (file)
     </layout>
    </widget>
   </widget>
+  <widget class="QDockWidget" name="errorsDock">
+   <property name="features">
+    <set>QDockWidget::AllDockWidgetFeatures</set>
+   </property>
+   <property name="windowTitle">
+    <string>Errors</string>
+   </property>
+   <attribute name="dockWidgetArea">
+    <number>8</number>
+   </attribute>
+   <widget class="QWidget" name="dockWidgetContents_4">
+    <layout class="QVBoxLayout" name="verticalLayout_4">
+     <item>
+      <widget class="QTreeWidget" name="errorsTreeWidget">
+       <column>
+        <property name="text">
+         <string>Index</string>
+        </property>
+       </column>
+       <column>
+        <property name="text">
+         <string>Name</string>
+        </property>
+       </column>
+       <column>
+        <property name="text">
+         <string>Error</string>
+        </property>
+       </column>
+      </widget>
+     </item>
+    </layout>
+   </widget>
+  </widget>
   <action name="actionExit">
    <property name="text">
     <string>Exit</string>
   </action>
   <zorder>stateDock</zorder>
   <zorder>vertexDataDock</zorder>
+  <zorder>errorsDock</zorder>
  </widget>
  <customwidgets>
   <customwidget>