]> git.cworth.org Git - vogl/blobdiff - src/vogleditor/vogleditor.cpp
UI: Fix issue #20: Search in the editor really slow
[vogl] / src / vogleditor / vogleditor.cpp
index 0fcca776583e7235c333bb2fa5f3ea4dde6d60ce..ea33ffa184714fef249f3354ad2075b11131ad2a 100644 (file)
@@ -119,7 +119,6 @@ VoglEditor::VoglEditor(QWidget *parent) :
    m_pTrimButton(NULL),
    m_pStopButton(NULL),
    m_pTraceReader(NULL),
-   m_pTraceWriter(NULL),
    m_pApicallTreeModel(NULL)
 {
    ui->setupUi(this);
@@ -133,6 +132,9 @@ VoglEditor::VoglEditor(QWidget *parent) :
    m_statusLabel->setBaseSize(150, 12);
    ui->statusBar->addWidget(m_statusLabel, 1);
 
+   // cache the original background color of the search text box
+   m_searchTextboxBackgroundColor = ui->searchTextBox->palette().base().color();
+
    // setup framebuffer tab
    QGridLayout* framebufferTab_layout = new QGridLayout;
    m_framebufferExplorer = new vogleditor_QFramebufferExplorer(ui->framebufferTab);
@@ -344,19 +346,11 @@ void VoglEditor::close_trace_file()
       vogl_delete(m_pTraceReader);
       m_pTraceReader = NULL;
 
-      if (m_pTraceWriter != NULL)
-      {
-          m_pTraceWriter->close();
-          vogl_delete(m_pTraceWriter);
-          m_pTraceWriter = NULL;
-      }
-
       setWindowTitle(g_PROJECT_NAME);
 
       m_openFilename.clear();
       m_backtraceToJsonMap.clear();
       m_backtraceDoc.clear();
-      m_searchApicallResults.clear();
 
       reset_tracefile_ui();
 
@@ -952,10 +946,6 @@ bool VoglEditor::open_trace_file(dynamic_string filename)
 
    vogl_ctypes trace_ctypes;
    trace_ctypes.init(m_pTraceReader->get_sof_packet().m_pointer_sizes);
-   m_pTraceWriter = vogl_new(vogl_trace_file_writer, &trace_ctypes);
-
-   dynamic_string traceSessionFilename = "vogleditor_session.bin";
-   m_pTraceWriter->open(traceSessionFilename.c_str());
 
    m_pApicallTreeModel = new vogleditor_QApiCallTreeModel(m_pTraceReader);
    ui->treeView->setModel(m_pApicallTreeModel);
@@ -1258,7 +1248,7 @@ void VoglEditor::reset_snapshot_ui()
 vogleditor_gl_state_snapshot* VoglEditor::findMostRecentSnapshot_helper(vogleditor_apiCallTreeItem* pItem, vogleditor_gl_state_snapshot*& pMostRecentSnapshot, const vogleditor_gl_state_snapshot* pCurSnapshot)
 {
     // check if this item has a snapshot shot
-    if (pItem->has_snapshot())
+    if (pItem->has_snapshot() && pItem->get_snapshot()->is_valid())
     {
         vogleditor_gl_state_snapshot* pTmp = pItem->get_snapshot();
         if (pTmp == pCurSnapshot)
@@ -1342,8 +1332,7 @@ void VoglEditor::update_ui_for_snapshot(vogleditor_gl_state_snapshot* pStateSnap
    // state viewer
    vogleditor_QStateTreeModel* pStateModel = new vogleditor_QStateTreeModel(NULL);
 
-   vogleditor_QApiCallTreeModel* pTreeModel = static_cast<vogleditor_QApiCallTreeModel*>(ui->treeView->model());
-   vogleditor_gl_state_snapshot* pBaseSnapshot = findMostRecentSnapshot(pTreeModel->root(), m_currentSnapshot);
+   vogleditor_gl_state_snapshot* pBaseSnapshot = findMostRecentSnapshot(m_pApicallTreeModel->root(), m_currentSnapshot);
    pStateModel->set_diff_base_snapshot(pBaseSnapshot);
 
    pStateModel->set_snapshot(pStateSnapshot);
@@ -1645,71 +1634,23 @@ void VoglEditor::selectApicallModelIndex(QModelIndex index, bool scrollTo, bool
     {
         ui->treeView->setCurrentIndex(index);
     }
-
-    if (m_searchApicallResults.size() > 0 && !ui->searchTextBox->text().isEmpty())
-    {
-        QItemSelectionModel* pSelection = ui->treeView->selectionModel();
-        for (int i = 0; i < m_searchApicallResults.size(); i++)
-        {
-            pSelection->select(m_searchApicallResults[i], QItemSelectionModel::Select | QItemSelectionModel::Rows);
-        }
-        ui->treeView->setSelectionModel(pSelection);
-    }
 }
 
 void VoglEditor::on_searchTextBox_textChanged(const QString &searchText)
 {
-    QModelIndex curSearchIndex = ui->treeView->currentIndex();
-    if (curSearchIndex.isValid() == false)
-    {
-        return;
-    }
-
-    // store original background color of the search text box so that it can be turned to red and later restored.
-    static const QColor sOriginalTextBoxBackground = ui->searchTextBox->palette().base().color();
+    QPalette palette(ui->searchTextBox->palette());
+    palette.setColor(QPalette::Base, m_searchTextboxBackgroundColor);
+    ui->searchTextBox->setPalette(palette);
 
-    // clear previous items
-    QItemSelectionModel* pSelection = ui->treeView->selectionModel();
-    if (pSelection != NULL)
-    {
-        for (int i = 0; i < m_searchApicallResults.size(); i++)
-        {
-            pSelection->select(m_searchApicallResults[i], QItemSelectionModel::Clear | QItemSelectionModel::Rows);
-        }
-        ui->treeView->setSelectionModel(pSelection);
-    }
-
-    // find new matches
-    m_searchApicallResults.clear();
     if (m_pApicallTreeModel != NULL)
     {
-        m_searchApicallResults = m_pApicallTreeModel->find_search_matches(searchText);
-    }
-
-    // if there are matches, restore the textbox background to its original color
-    if (m_searchApicallResults.size() > 0)
-    {
-        QPalette palette(ui->searchTextBox->palette());
-        palette.setColor(QPalette::Base, sOriginalTextBoxBackground);
-        ui->searchTextBox->setPalette(palette);
+        m_pApicallTreeModel->set_highlight_search_string(searchText);
     }
 
-    // select new items
-    if (!searchText.isEmpty())
-    {
-        if (m_searchApicallResults.size() > 0)
-        {
-            // scroll to the first result, but don't select it
-            selectApicallModelIndex(m_searchApicallResults[0], true, false);
-        }
-        else
-        {
-            // no items were found, so set the textbox background to red
-            QPalette palette(ui->searchTextBox->palette());
-            palette.setColor(QPalette::Base, Qt::red);
-            ui->searchTextBox->setPalette(palette);
-        }
-    }
+    // need to briefly give the treeview focus so that it properly redraws and highlights the matching rows
+    // then return focus to the search textbox so that typed keys are not lost
+    ui->treeView->setFocus();
+    ui->searchTextBox->setFocus();
 }
 
 void VoglEditor::on_searchNextButton_clicked()
@@ -1717,7 +1658,11 @@ void VoglEditor::on_searchNextButton_clicked()
     if (m_pApicallTreeModel != NULL)
     {
         QModelIndex index = m_pApicallTreeModel->find_next_search_result(m_pCurrentCallTreeItem, ui->searchTextBox->text());
-        selectApicallModelIndex(index, true, true);
+        if (index.isValid())
+        {
+            selectApicallModelIndex(index, true, true);
+            ui->treeView->setFocus();
+        }
     }
 }
 
@@ -1726,7 +1671,11 @@ void VoglEditor::on_searchPrevButton_clicked()
     if (m_pApicallTreeModel != NULL)
     {
         QModelIndex index = m_pApicallTreeModel->find_prev_search_result(m_pCurrentCallTreeItem, ui->searchTextBox->text());
-        selectApicallModelIndex(index, true, true);
+        if (index.isValid())
+        {
+            selectApicallModelIndex(index, true, true);
+            ui->treeView->setFocus();
+        }
     }
 }
 
@@ -1735,8 +1684,11 @@ void VoglEditor::on_prevSnapshotButton_clicked()
     if (m_pApicallTreeModel != NULL)
     {
         vogleditor_apiCallTreeItem* pPrevItemWithSnapshot = m_pApicallTreeModel->find_prev_snapshot(m_pCurrentCallTreeItem);
-        selectApicallModelIndex(m_pApicallTreeModel->indexOf(pPrevItemWithSnapshot), true, true);
-        ui->treeView->setFocus();
+        if (pPrevItemWithSnapshot != NULL)
+        {
+            selectApicallModelIndex(m_pApicallTreeModel->indexOf(pPrevItemWithSnapshot), true, true);
+            ui->treeView->setFocus();
+        }
     }
 }
 
@@ -1745,8 +1697,11 @@ void VoglEditor::on_nextSnapshotButton_clicked()
     if (m_pApicallTreeModel != NULL)
     {
         vogleditor_apiCallTreeItem* pNextItemWithSnapshot = m_pApicallTreeModel->find_next_snapshot(m_pCurrentCallTreeItem);
-        selectApicallModelIndex(m_pApicallTreeModel->indexOf(pNextItemWithSnapshot), true, true);
-        ui->treeView->setFocus();
+        if (pNextItemWithSnapshot != NULL)
+        {
+            selectApicallModelIndex(m_pApicallTreeModel->indexOf(pNextItemWithSnapshot), true, true);
+            ui->treeView->setFocus();
+        }
     }
 }
 
@@ -1755,8 +1710,11 @@ void VoglEditor::on_prevDrawcallButton_clicked()
     if (m_pApicallTreeModel != NULL)
     {
         vogleditor_apiCallTreeItem* pPrevItem = m_pApicallTreeModel->find_prev_drawcall(m_pCurrentCallTreeItem);
-        selectApicallModelIndex(m_pApicallTreeModel->indexOf(pPrevItem), true, true);
-        ui->treeView->setFocus();
+        if (pPrevItem != NULL)
+        {
+            selectApicallModelIndex(m_pApicallTreeModel->indexOf(pPrevItem), true, true);
+            ui->treeView->setFocus();
+        }
     }
 }
 
@@ -1765,12 +1723,14 @@ void VoglEditor::on_nextDrawcallButton_clicked()
     if (m_pApicallTreeModel != NULL)
     {
         vogleditor_apiCallTreeItem* pNextItem = m_pApicallTreeModel->find_next_drawcall(m_pCurrentCallTreeItem);
-        selectApicallModelIndex(m_pApicallTreeModel->indexOf(pNextItem), true, true);
-        ui->treeView->setFocus();
+        if (pNextItem != NULL)
+        {
+            selectApicallModelIndex(m_pApicallTreeModel->indexOf(pNextItem), true, true);
+            ui->treeView->setFocus();
+        }
     }
 }
 
-
 void VoglEditor::on_program_edited(vogl_program_state* pNewProgramState)
 {
     VOGL_NOTE_UNUSED(pNewProgramState);
@@ -1854,3 +1814,23 @@ void VoglEditor::on_actionOpen_Session_triggered()
 
     setCursor(origCursor);
 }
+
+void VoglEditor::on_searchTextBox_returnPressed()
+{
+    if (m_pApicallTreeModel != NULL)
+    {
+        QModelIndex index = m_pApicallTreeModel->find_next_search_result(m_pCurrentCallTreeItem, ui->searchTextBox->text());
+        if (index.isValid())
+        {
+            // a valid item was found, scroll to it and select it
+            selectApicallModelIndex(index, true, true);
+        }
+        else
+        {
+            // no items were found, so set the textbox background to red (it will get cleared to the original color if the user edits the search text)
+            QPalette palette(ui->searchTextBox->palette());
+            palette.setColor(QPalette::Base, Qt::red);
+            ui->searchTextBox->setPalette(palette);
+        }
+    }
+}