From 758cf55c5db92759dcf0c8c4ee332cbe25554ea0 Mon Sep 17 00:00:00 2001 From: k1988 Date: Wed, 27 May 2020 13:28:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1.=E6=94=AF=E6=8C=81=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E4=B8=AD=E4=BC=A0=E9=80=92=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQLiteExplorer/main.cpp | 15 +++++++++++++++ SQLiteExplorer/mainwindow.h | 5 ++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/SQLiteExplorer/main.cpp b/SQLiteExplorer/main.cpp index 59e21a9..c1ebc6b 100644 --- a/SQLiteExplorer/main.cpp +++ b/SQLiteExplorer/main.cpp @@ -1,5 +1,7 @@ #include "mainwindow.h" #include +#include +#include int main(int argc, char *argv[]) { @@ -8,5 +10,18 @@ int main(int argc, char *argv[]) w.resize(1600, 800); w.show(); + if (argc > 1) + { + auto path = argv[1]; + QFileInfo fileInfo(path); + std::set validSuffix = { + "db","sqlite" + }; + if(fileInfo.isFile() && validSuffix.count(fileInfo.suffix().toLower()) > 0) + { + w.openDatabaseFile(path); + } + } + return a.exec(); } diff --git a/SQLiteExplorer/mainwindow.h b/SQLiteExplorer/mainwindow.h index fdfe2a6..4ef6282 100644 --- a/SQLiteExplorer/mainwindow.h +++ b/SQLiteExplorer/mainwindow.h @@ -51,6 +51,8 @@ public: return m_pCurSQLite3DB; } + bool openDatabaseFile(const QString& path); + protected: void dragEnterEvent(QDragEnterEvent* e); void dropEvent(QDropEvent* e); @@ -71,9 +73,6 @@ private Q_SLOTS: void onVacuumActionTriggered(); void onAboutActionTriggered(); -private: - bool openDatabaseFile(const QString& path); - private: // Menu and Tool QAction* m_pOpenAction; -- Gitee From aeeb55bdd410beba8801fa38c5810c63283c2856 Mon Sep 17 00:00:00 2001 From: k1988 Date: Wed, 27 May 2020 15:42:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1.HexWindow=E4=B8=AD=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=A0=91=E3=80=81=E8=AE=B0=E5=BD=95=E8=A1=A8=E5=92=8CHex?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E4=B8=89=E6=96=B9=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQLiteExplorer/HexWindow.cpp | 65 +++++++++++++++++++++++++++++++++--- SQLiteExplorer/HexWindow.h | 4 +++ 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/SQLiteExplorer/HexWindow.cpp b/SQLiteExplorer/HexWindow.cpp index 905e325..df804a2 100644 --- a/SQLiteExplorer/HexWindow.cpp +++ b/SQLiteExplorer/HexWindow.cpp @@ -36,7 +36,7 @@ HexWindow::HexWindow(QWidget *parent) : m_pPageView->setAlternatingRowColors(true); m_pPageView->setStyleSheet("QTableView{background-color: rgb(250, 250, 115);" "alternate-background-color: rgb(141, 163, 215);}"); - + connect(m_pPageView->selectionModel(),SIGNAL(currentRowChanged(const QModelIndex &,const QModelIndex &)), this, SLOT(onPageCurrentRowChanged(const QModelIndex &,const QModelIndex &))); m_pHSplitter->addWidget(m_pHexEdit); m_pHSplitter->addWidget(m_pPageView); @@ -47,6 +47,7 @@ HexWindow::HexWindow(QWidget *parent) : m_pSplitter->addWidget(m_pTableWdiget); m_pTableWdiget->setSelectionBehavior(QAbstractItemView::SelectRows); m_pTableWdiget->setSelectionMode(QAbstractItemView::SingleSelection); + connect(m_pTableWdiget, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(onTableCurrentCellChanged(int,int,int,int))); setStyleSheet("QTableWidget::item:selected { background-color: rgb(143, 221, 119) }"); @@ -196,9 +197,9 @@ void HexWindow::setPageHdrData(PageType type, ContentArea& pageHeaderArea, Conte { if(m_pCurSQLite3DB == NULL) return; int base = 10; - QStandardItem* pghdr = new QStandardItem("PageHdr"); - m_pPageViewModel->appendRow(pghdr); int pghdrOffset = (pgno==1?100:0); + QStandardItem* pghdr = GetItem(pghdrOffset, pageHeaderArea.m_len, "PageHdr"); + m_pPageViewModel->appendRow(pghdr); int row = 0; int col = 1; m_pPageViewModel->setItem(pghdr->row(), col++, new QStandardItem(QString("PageHdr"))); @@ -283,7 +284,7 @@ void HexWindow::setPageHdrData(PageType type, ContentArea& pageHeaderArea, Conte pghdr->setChild(row, col++, new QStandardItem(upperHex(raw, pghdrOffset+8, 4))); } - QStandardItem* cellPtr = new QStandardItem("CellPtr"); + QStandardItem* cellPtr = GetItem(cellidxArea.m_startAddr, cellidxArea.m_len, "CellPtr"); m_pPageViewModel->appendRow(cellPtr); col = 1; @@ -375,7 +376,7 @@ QStandardItem* HexWindow::setCellData(QStandardItem* parentItem, CSQLite3Payload qDebug() << "1"; int col = 0; int row = cells->rowCount(); - QStandardItem* cell = new QStandardItem(QString("Cell[%1]").arg(row)); + QStandardItem* cell = GetItem(area.m_startAddr,area.m_len,QString("Cell[%1]").arg(row)); cells->setChild(row, col++, cell); QString cellDesc = QString::fromStdString(raw.substr(area.m_startAddr, area.m_len)); cellDesc = cellDesc.remove("\r").remove("\n"); @@ -546,6 +547,7 @@ QStandardItem *HexWindow::GetItem(int start, i64 len, QString txt) for(int i=start; iclear(); m_mapItems.clear(); + m_mapItemsPos.clear(); m_curPageNo = pgno; QStringList headers; @@ -1028,8 +1031,10 @@ void HexWindow::onCurrentAddressChanged(qint64 address) if(address >= start && address <= end) { int row = it - m_payloadArea.begin(); + m_pTableWdiget->blockSignals(true); m_pTableWdiget->selectRow(row); m_pTableWdiget->showRow(row); + m_pTableWdiget->blockSignals(false); break; } } @@ -1059,6 +1064,56 @@ void HexWindow::onCheckBoxStatChanged(bool stat) document->endMetadata(); } +void HexWindow::onPageCurrentRowChanged(const QModelIndex ¤t, const QModelIndex &previous) +{ + auto item = m_pPageViewModel->itemFromIndex(current); + if (!item) return; + + // qDebug() << "current is " << current.row() << "," << current.column() << " " << item->text(); + if (m_mapItemsPos.contains(item)) + { + auto pos = m_mapItemsPos[item]; + // qDebug() << "address of select node is " << pos.first << " - " << pos.first + pos.second; + m_pHexEdit->blockSignals(true); + m_pHexEdit->document()->cursor()->setSelectionRange(pos.first, pos.second); + m_pHexEdit->blockSignals(false); + + m_pTableWdiget->blockSignals(true); + for(auto it=m_payloadArea.begin(); it!=m_payloadArea.end(); ++it) + { + i64 start = it->m_startAddr; + i64 end = start + it->m_len; + if(pos.first >= start && pos.first + pos.second <= end) + { + int row = it - m_payloadArea.begin(); + m_pTableWdiget->selectRow(row); + m_pTableWdiget->showRow(row); + break; + } + } + m_pTableWdiget->blockSignals(false); + } +} + +void HexWindow::onTableCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn) +{ + if (currentRow != previousRow) + { + // qDebug() << "table current row changed to " << currentRow; + + if (m_payloadArea.size() <= currentRow) return; + + auto playload = m_payloadArea[currentRow]; + auto pItems = m_mapItemsPos.keys({playload.m_startAddr, playload.m_len}); + if (!pItems.empty()) + { + auto pItem = pItems[0]; + m_pPageView->selectionModel()->setCurrentIndex(pItem->index(), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + m_pPageView->scrollTo(pItem->index(), QTreeView::PositionAtTop); + } + } +} + void HexWindow::setPushBtnStats() { int curIdx = ui->comboBox->currentIndex(); diff --git a/SQLiteExplorer/HexWindow.h b/SQLiteExplorer/HexWindow.h index 9cef0de..5e7012d 100644 --- a/SQLiteExplorer/HexWindow.h +++ b/SQLiteExplorer/HexWindow.h @@ -41,6 +41,7 @@ public: QStandardItem *setCellData(QStandardItem *parentItem, CSQLite3Payload& payload, ContentArea area, string raw); QStandardItem* GetItem(int start, i64 len, QString txt); + public slots: void onPageIdSelect(int pgno, PageType type); void onPageTypeChanged(const QString& item); @@ -52,6 +53,8 @@ public slots: void onCurrentAddressChanged(qint64 address); void onCheckBoxStatChanged(bool stat); + void onPageCurrentRowChanged(const QModelIndex ¤t, const QModelIndex &previous); + void onTableCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); private: void setPushBtnStats(); @@ -81,6 +84,7 @@ private: QStringList m_pageNoAndTypes; QMap m_mapItems; + QMap > m_mapItemsPos; uint m_curPageNo; }; -- Gitee