]> git.cworth.org Git - apitrace/commitdiff
Highly optimize searching and fix a crash.
authorZack Rusin <zack@kde.org>
Wed, 13 Apr 2011 03:39:13 +0000 (23:39 -0400)
committerZack Rusin <zack@kde.org>
Wed, 13 Apr 2011 03:39:13 +0000 (23:39 -0400)
gui/apitracefilter.cpp
gui/apitracefilter.h
gui/apitracemodel.cpp
gui/apitracemodel.h
gui/mainwindow.cpp
gui/searchwidget.cpp
gui/searchwidget.h

index 7580bba2dd899e12d5dcfe5f011e1c8754d783c2..50b854e57336548a9c90e33457d79b11810a4caa 100644 (file)
@@ -96,4 +96,11 @@ QModelIndex ApiTraceFilter::callIndex(int callIdx) const
     return mapFromSource(index);
 }
 
+QModelIndex ApiTraceFilter::indexForCall(ApiTraceCall *call) const
+{
+    ApiTraceModel *model = static_cast<ApiTraceModel *>(sourceModel());
+    QModelIndex index = model->indexForCall(call);
+    return mapFromSource(index);
+}
+
 #include "apitracefilter.moc"
index 2bd85575cdf90b7b12f93a34fdf53bc6d952ea82..7ceabe6fb1b26ebfbd114d42d061550fe3ce73a3 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <QSortFilterProxyModel>
 
+class ApiTraceCall;
+
 class ApiTraceFilter : public QSortFilterProxyModel
 {
     Q_OBJECT
@@ -24,6 +26,7 @@ public:
     void setFilterString(const QString &text);
 
     QModelIndex callIndex(int callNum) const;
+    QModelIndex indexForCall(ApiTraceCall *call) const;
 protected:
     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
 
index 2b4b6bb2126ae52900e7592c5b397103bda14333..d3f3e6a7545aedbcef8d6269de04fe05b358ac14 100644 (file)
@@ -256,9 +256,12 @@ void ApiTraceModel::stateSetOnEvent(ApiTraceEvent *event)
 QModelIndex ApiTraceModel::callIndex(int callNum) const
 {
     ApiTraceCall *call = m_trace->callWithIndex(callNum);
+    return indexForCall(call);
+}
 
+QModelIndex ApiTraceModel::indexForCall(ApiTraceCall *call) const
+{
     if (!call) {
-        qDebug()<<"couldn't find call at "<<callNum;
         return QModelIndex();
     }
 
@@ -267,7 +270,7 @@ QModelIndex ApiTraceModel::callIndex(int callNum) const
 
     int row = frame->calls.indexOf(call);
     if (row < 0) {
-        qDebug() << "Couldn't find call num "<<callNum<<" inside parent!";
+        qDebug() << "Couldn't find call num "<<call->index<<" inside parent!";
         return QModelIndex();
     }
     return createIndex(row, 0, call);
index 345cd133c5c8ca9b1db823b7822c50178a03a1b1..7a0394b2bc7facae2c5aa84766d04c0afdb3a5d3 100644 (file)
@@ -26,6 +26,7 @@ public:
     void stateSetOnEvent(ApiTraceEvent *event);
 
     QModelIndex callIndex(int callNum) const;
+    QModelIndex indexForCall(ApiTraceCall *call) const;
 
 public:
     /* QAbstractItemModel { */
index 35c287ac2af78e10a2a4cc74db802f8e388899ee..ff51d956be5150c6aed258393ce2fc4bff4a3854 100644 (file)
@@ -650,8 +650,19 @@ void MainWindow::slotSearch()
 void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitivity)
 {
     QModelIndex index = m_ui.callView->currentIndex();
-    ApiTraceEvent *event =
-        index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+    ApiTraceEvent *event = 0;
+
+
+    if (!index.isValid()) {
+        index = m_proxyModel->index(0, 0, QModelIndex());
+        if (!index.isValid()) {
+            qDebug()<<"no currently valid index";
+            m_searchWidget->setFound(false);
+            return;
+        }
+    }
+
+    event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
     ApiTraceCall *call = 0;
 
     if (event->type() == ApiTraceCall::Call)
@@ -673,7 +684,7 @@ void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitiv
         ApiTraceCall *testCall = calls[i];
         QString txt = testCall->filterText();
         if (txt.contains(str, sensitivity)) {
-            QModelIndex index = m_proxyModel->callIndex(testCall->index);
+            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()) {
@@ -689,8 +700,19 @@ void MainWindow::slotSearchNext(const QString &str, Qt::CaseSensitivity sensitiv
 void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitivity)
 {
     QModelIndex index = m_ui.callView->currentIndex();
-    ApiTraceEvent *event =
-        index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
+    ApiTraceEvent *event = 0;
+
+
+    if (!index.isValid()) {
+        index = m_proxyModel->index(0, 0, QModelIndex());
+        if (!index.isValid()) {
+            qDebug()<<"no currently valid index";
+            m_searchWidget->setFound(false);
+            return;
+        }
+    }
+
+    event = index.data(ApiTraceModel::EventRole).value<ApiTraceEvent*>();
     ApiTraceCall *call = 0;
 
     if (event->type() == ApiTraceCall::Call)
@@ -712,7 +734,7 @@ void MainWindow::slotSearchPrev(const QString &str, Qt::CaseSensitivity sensitiv
         ApiTraceCall *testCall = calls[i];
         QString txt = testCall->filterText();
         if (txt.contains(str, sensitivity)) {
-            QModelIndex index = m_proxyModel->callIndex(testCall->index);
+            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()) {
index 6f9bc9408123ce65488997a358c28e81e767ea5e..45762b3f3749f00e7c5ee438df1fa03f2f85e3eb 100644 (file)
@@ -44,9 +44,6 @@ void SearchWidget::slotCancel()
 
 void SearchWidget::showEvent(QShowEvent *event)
 {
-    m_ui.lineEdit->selectAll();
-    m_ui.lineEdit->setFocus(Qt::ShortcutFocusReason);
-    m_ui.lineEdit->setPalette(m_origPalette);
     return QWidget::showEvent(event);
 }
 
@@ -77,4 +74,12 @@ void SearchWidget::setFound(bool found)
     m_ui.notFoundLabel->setVisible(!found);
 }
 
+void SearchWidget::show()
+{
+    QWidget::show();
+    m_ui.lineEdit->selectAll();
+    m_ui.lineEdit->setFocus(Qt::ShortcutFocusReason);
+    m_ui.lineEdit->setPalette(m_origPalette);
+}
+
 #include "searchwidget.moc"
index d10530327191012fa50484b8bee0ee4bd4c3e3b7..f59b4a0c2e85ce70546dfcda3ed1484a46834761 100644 (file)
@@ -14,6 +14,7 @@ public:
     SearchWidget(QWidget *parent=0);
 
     void setFound(bool f);
+    void show();
 signals:
     void searchNext(const QString &str, Qt::CaseSensitivity cs = Qt::CaseInsensitive);
     void searchPrev(const QString &str, Qt::CaseSensitivity cs = Qt::CaseInsensitive);