From: Michael Sartain Date: Tue, 18 Mar 2014 23:44:09 +0000 (-0700) Subject: Merge pull request #23 from kingtaurus/master X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=5c2fb871a2148f15e3d90670ee1fbebd49117776;hp=b58c5c28be59e706ae086d86bd26030ed8931c69;p=vogl Merge pull request #23 from kingtaurus/master Proposed changes to fix issue #16. --- diff --git a/qtcreator/qtcreator.md b/qtcreator/qtcreator.md index 96b6f62..0e19829 100644 --- a/qtcreator/qtcreator.md +++ b/qtcreator/qtcreator.md @@ -22,7 +22,7 @@ You should now be able to click in bottom left "Type to locate" control (or hit * Mouse over the "Make: make" step and click the 'x' to delete it. * Click , and select "Custom Process Step". - Command: /home/mikesart/dev/voglproj/vogl/bin/mkvogl.sh + Command: %{buildDir}/../bin/mkvogl.sh Arguments: --amd64 --debug 3>&1 1>&2 2>&3 * Now select "Choose Build / Build Project..." or (Ctrl+B) @@ -34,7 +34,7 @@ You should now be able to click in bottom left "Type to locate" control (or hit * Mouse over the "Make: make clean" step and click the 'x' to delete it. * Click "Add Clean Step", select "Custom Process Step". - Command: /home/mikesart/dev/voglproj/vogl/bin/mkvogl.sh + Command: %{buildDir}/../bin/mkvogl.sh Arguments: --amd64 --debug --cleanonly @@ -45,9 +45,9 @@ You should now be able to click in bottom left "Type to locate" control (or hit * Click "Add"; select "Clone selected"; follow steps below * Repeat the steps above for the remaining build configurations: - * amd64_release": Arguments: --amd64 --release --verbose 3>&1 1>&2 2>&3 - * i386_debug: Arguments: --i386 --debug --verbose 3>&1 1>&2 2>&3 - * i386_release": Arguments: --i386 --release --verbose 3>&1 1>&2 2>&3 + * "amd64_release": Arguments: --amd64 --release --verbose 3>&1 1>&2 2>&3 + * "i386_debug": Arguments: --i386 --debug --verbose 3>&1 1>&2 2>&3 + * "i386_release": Arguments: --i386 --release --verbose 3>&1 1>&2 2>&3 -Not that you can use the "--usemake" flag with mkvolg.sh if you don't want to use Ninja. If you do this, remove the "3>&1 1>&2 2>&3" redirections also. +Note that you can use the "--usemake" flag with mkvolg.sh if you don't want to use Ninja. If you do this, remove the "3>&1 1>&2 2>&3" redirections also. diff --git a/src/vogleditor/vogleditor.cpp b/src/vogleditor/vogleditor.cpp index a7c199c..ea33ffa 100644 --- a/src/vogleditor/vogleditor.cpp +++ b/src/vogleditor/vogleditor.cpp @@ -132,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); @@ -348,7 +351,6 @@ void VoglEditor::close_trace_file() m_openFilename.clear(); m_backtraceToJsonMap.clear(); m_backtraceDoc.clear(); - m_searchApicallResults.clear(); reset_tracefile_ui(); @@ -1632,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(); - - // 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); - } + QPalette palette(ui->searchTextBox->palette()); + palette.setColor(QPalette::Base, m_searchTextboxBackgroundColor); + ui->searchTextBox->setPalette(palette); - // find new matches - m_searchApicallResults.clear(); if (m_pApicallTreeModel != NULL) { - m_searchApicallResults = m_pApicallTreeModel->find_search_matches(searchText); + m_pApicallTreeModel->set_highlight_search_string(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); - } - - // 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() @@ -1704,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(); + } } } @@ -1713,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(); + } } } @@ -1722,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(); + } } } @@ -1732,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(); + } } } @@ -1742,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(); + } } } @@ -1752,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); @@ -1841,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); + } + } +} diff --git a/src/vogleditor/vogleditor.h b/src/vogleditor/vogleditor.h index ad007e2..30ffd58 100644 --- a/src/vogleditor/vogleditor.h +++ b/src/vogleditor/vogleditor.h @@ -110,6 +110,8 @@ private slots: void on_actionOpen_Session_triggered(); + void on_searchTextBox_returnPressed(); + private: Ui::VoglEditor* ui; @@ -166,8 +168,7 @@ private: vogleditor_apiCallTimelineModel* m_pTimelineModel; vogleditor_QApiCallTreeModel* m_pApicallTreeModel; - - QModelIndexList m_searchApicallResults; + QColor m_searchTextboxBackgroundColor; }; #endif // VOGLEDITOR_H diff --git a/src/vogleditor/vogleditor_apicalltreeitem.cpp b/src/vogleditor/vogleditor_apicalltreeitem.cpp index 32ff10a..3fd2d7f 100644 --- a/src/vogleditor/vogleditor_apicalltreeitem.cpp +++ b/src/vogleditor/vogleditor_apicalltreeitem.cpp @@ -35,7 +35,8 @@ vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_QApiCallTreeMo : m_parentItem(NULL), m_pApiCallItem(NULL), m_pFrameItem(NULL), - m_pModel(pModel) + m_pModel(pModel), + m_localRowIndex(0) { m_columnData[VOGL_ACTC_APICALL] = "API Call"; m_columnData[VOGL_ACTC_INDEX] = "Index"; @@ -51,7 +52,8 @@ vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(vogleditor_frameItem* fra : m_parentItem(parent), m_pApiCallItem(NULL), m_pFrameItem(frameItem), - m_pModel(NULL) + m_pModel(NULL), + m_localRowIndex(0) { if (frameItem != NULL) { @@ -71,7 +73,8 @@ vogleditor_apiCallTreeItem::vogleditor_apiCallTreeItem(QString nodeText, vogledi : m_parentItem(parent), m_pApiCallItem(apiCallItem), m_pFrameItem(NULL), - m_pModel(NULL) + m_pModel(NULL), + m_localRowIndex(0) { m_columnData[VOGL_ACTC_APICALL] = nodeText; @@ -122,7 +125,8 @@ vogleditor_apiCallTreeItem* vogleditor_apiCallTreeItem::parent() const void vogleditor_apiCallTreeItem::appendChild(vogleditor_apiCallTreeItem* pChild) { - m_childItems.append(pChild); + pChild->m_localRowIndex = m_childItems.size(); + m_childItems.append(pChild); } int vogleditor_apiCallTreeItem::childCount() const @@ -252,8 +256,5 @@ QVariant vogleditor_apiCallTreeItem::columnData(int column, int role) const int vogleditor_apiCallTreeItem::row() const { // note, this is just the row within the current level of the hierarchy - if (m_parentItem) - return m_parentItem->m_childItems.indexOf(const_cast(this)); - - return 0; + return m_localRowIndex; } diff --git a/src/vogleditor/vogleditor_apicalltreeitem.h b/src/vogleditor/vogleditor_apicalltreeitem.h index 9957a72..b76b0e1 100644 --- a/src/vogleditor/vogleditor_apicalltreeitem.h +++ b/src/vogleditor/vogleditor_apicalltreeitem.h @@ -93,6 +93,7 @@ private: vogleditor_apiCallItem* m_pApiCallItem; vogleditor_frameItem* m_pFrameItem; vogleditor_QApiCallTreeModel* m_pModel; + int m_localRowIndex; }; #endif // VOGLEDITOR_APICALLTREEITEM_H diff --git a/src/vogleditor/vogleditor_qapicalltreemodel.cpp b/src/vogleditor/vogleditor_qapicalltreemodel.cpp index e34cc5b..e661f1c 100644 --- a/src/vogleditor/vogleditor_qapicalltreemodel.cpp +++ b/src/vogleditor/vogleditor_qapicalltreemodel.cpp @@ -312,9 +312,23 @@ QVariant vogleditor_QApiCallTreeModel::data(const QModelIndex &index, int role) if (!index.isValid()) return QVariant(); - vogleditor_apiCallTreeItem *item = static_cast(index.internalPointer()); + vogleditor_apiCallTreeItem* pItem = static_cast(index.internalPointer()); - return item->columnData(index.column(), role); + // highlight the API call cell if it has a substring which matches the searchString + if (role == Qt::BackgroundRole && index.column() == VOGL_ACTC_APICALL) + { + if (!m_searchString.isEmpty()) + { + QVariant data = pItem->columnData(VOGL_ACTC_APICALL, Qt::DisplayRole); + QString string = data.toString(); + if (string.contains(m_searchString, Qt::CaseInsensitive)) + { + return QColor(Qt::yellow); + } + } + } + + return pItem->columnData(index.column(), role); } Qt::ItemFlags vogleditor_QApiCallTreeModel::flags(const QModelIndex &index) const @@ -334,44 +348,35 @@ QVariant vogleditor_QApiCallTreeModel::headerData(int section, Qt::Orientation o return QVariant(); } -QModelIndexList vogleditor_QApiCallTreeModel::find_search_matches(const QString searchText) +void vogleditor_QApiCallTreeModel::set_highlight_search_string(const QString searchString) +{ + m_searchString = searchString; +} + +QModelIndex vogleditor_QApiCallTreeModel::find_prev_search_result(vogleditor_apiCallTreeItem* start, const QString searchText) { QLinkedListIterator iter(m_itemList); - QModelIndexList matches; - // iterate through all items and find matching text - while (iter.hasNext()) + if (start != NULL) { - vogleditor_apiCallTreeItem* pItem = iter.peekNext(); - QVariant data = pItem->columnData(VOGL_ACTC_APICALL, Qt::DisplayRole); - QString string = data.toString(); - if (string.contains(searchText, Qt::CaseInsensitive)) + if (iter.findNext(start) == false) { - matches.push_back(indexOf(pItem)); + // the object wasn't found in the list, so return a default (invalid) item + return QModelIndex(); } - iter.next(); + // need to back up past the current item + iter.previous(); } - - return matches; -} - -QModelIndex vogleditor_QApiCallTreeModel::find_prev_search_result(vogleditor_apiCallTreeItem* start, const QString searchText) -{ - QLinkedListIterator iter(m_itemList); - - if (iter.findNext(start) == false) + else { - // the object wasn't found in the list, so just return the same item - return indexOf(start); + // set the iterator to the back so that searching starts from the end of the list + iter.toBack(); } - // need to back up past the current item - iter.previous(); - // now the iterator is pointing to the desired start object in the list, // continually check the prev item and find one with a snapshot - vogleditor_apiCallTreeItem* pFound = start; + vogleditor_apiCallTreeItem* pFound = NULL; while (iter.hasPrevious()) { vogleditor_apiCallTreeItem* pItem = iter.peekPrevious(); @@ -391,18 +396,20 @@ QModelIndex vogleditor_QApiCallTreeModel::find_prev_search_result(vogleditor_api QModelIndex vogleditor_QApiCallTreeModel::find_next_search_result(vogleditor_apiCallTreeItem* start, const QString searchText) { - QLinkedListIterator iter(m_itemList); - if (iter.findNext(start) == false) + if (start != NULL) { - // the object wasn't found in the list, so just return the same item - return indexOf(start); + if (iter.findNext(start) == false) + { + // the object wasn't found in the list, so return a default (invalid) item + return QModelIndex(); + } } // now the iterator is pointing to the desired start object in the list, // continually check the next item and find one with a snapshot - vogleditor_apiCallTreeItem* pFound = start; + vogleditor_apiCallTreeItem* pFound = NULL; while (iter.hasNext()) { vogleditor_apiCallTreeItem* pItem = iter.peekNext(); @@ -424,18 +431,26 @@ vogleditor_apiCallTreeItem* vogleditor_QApiCallTreeModel::find_prev_snapshot(vog { QLinkedListIterator iter(m_itemList); - if (iter.findNext(start) == false) + if (start != NULL) { - // the object wasn't found in the list, so just return the same item - return start; - } + if (iter.findNext(start) == false) + { + // the object wasn't found in the list + return NULL; + } - // need to back up past the current item - iter.previous(); + // need to back up past the current item + iter.previous(); + } + else + { + // set the iterator to the back so that searching starts from the end of the list + iter.toBack(); + } // now the iterator is pointing to the desired start object in the list, // continually check the prev item and find one with a snapshot - vogleditor_apiCallTreeItem* pFound = start; + vogleditor_apiCallTreeItem* pFound = NULL; while (iter.hasPrevious()) { if (iter.peekPrevious()->has_snapshot()) @@ -459,14 +474,14 @@ vogleditor_apiCallTreeItem* vogleditor_QApiCallTreeModel::find_next_snapshot(vog { if (iter.findNext(start) == false) { - // the object wasn't found in the list, so just return the same item - return start; + // the object wasn't found in the list + return NULL; } } // now the iterator is pointing to the desired start object in the list, // continually check the next item and find one with a snapshot - vogleditor_apiCallTreeItem* pFound = start; + vogleditor_apiCallTreeItem* pFound = NULL; while (iter.hasNext()) { if (iter.peekNext()->has_snapshot()) @@ -486,18 +501,26 @@ vogleditor_apiCallTreeItem *vogleditor_QApiCallTreeModel::find_prev_drawcall(vog { QLinkedListIterator iter(m_itemList); - if (iter.findNext(start) == false) + if (start != NULL) { - // the object wasn't found in the list, so just return the same item - return start; - } + if (iter.findNext(start) == false) + { + // the object wasn't found in the list + return NULL; + } - // need to back up past the current item - iter.previous(); + // need to back up past the current item + iter.previous(); + } + else + { + // set the iterator to the back so that searching starts from the end of the list + iter.toBack(); + } // now the iterator is pointing to the desired start object in the list, // continually check the prev item and find one with a snapshot - vogleditor_apiCallTreeItem* pFound = start; + vogleditor_apiCallTreeItem* pFound = NULL; while (iter.hasPrevious()) { vogleditor_apiCallTreeItem* pItem = iter.peekPrevious(); @@ -524,13 +547,13 @@ vogleditor_apiCallTreeItem *vogleditor_QApiCallTreeModel::find_next_drawcall(vog if (iter.findNext(start) == false) { - // the object wasn't found in the list, so just return the same item - return start; + // the object wasn't found in the list + return NULL; } // now the iterator is pointing to the desired start object in the list, // continually check the next item and find one with a snapshot - vogleditor_apiCallTreeItem* pFound = start; + vogleditor_apiCallTreeItem* pFound = NULL; while (iter.hasNext()) { vogleditor_apiCallTreeItem* pItem = iter.peekNext(); diff --git a/src/vogleditor/vogleditor_qapicalltreemodel.h b/src/vogleditor/vogleditor_qapicalltreemodel.h index 91305c8..dab3da9 100644 --- a/src/vogleditor/vogleditor_qapicalltreemodel.h +++ b/src/vogleditor/vogleditor_qapicalltreemodel.h @@ -61,7 +61,7 @@ public: return m_rootItem; } - QModelIndexList find_search_matches(const QString searchText); + void set_highlight_search_string(const QString searchString); QModelIndex find_prev_search_result(vogleditor_apiCallTreeItem* start, const QString searchText); QModelIndex find_next_search_result(vogleditor_apiCallTreeItem* start, const QString searchText); @@ -82,6 +82,7 @@ private: vogleditor_apiCallTreeItem* m_rootItem; vogl_ctypes m_trace_ctypes; QLinkedList m_itemList; + QString m_searchString; void setupModelData(vogl_trace_file_reader* pTrace_reader, vogleditor_apiCallTreeItem* parent);