From cd2fe8049f16103ab88c665b53667c1bbd69b4ac Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Wed, 29 Jun 2011 18:40:04 +0200 Subject: [PATCH] gui: synchronize result list and table when feasible --- src/qtgui/rclmain_w.cpp | 25 +++++++++++++++++++++---- src/qtgui/rclmain_w.h | 1 + src/qtgui/restable.cpp | 18 ++++++++++++++++++ src/qtgui/restable.h | 3 +++ src/query/reslistpager.cpp | 26 ++++++++++++++++++++++++++ src/query/reslistpager.h | 1 + 6 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 9f0608c9..291ca997 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -955,6 +955,21 @@ void RclMain::on_actionShowResultsAsTable_toggled(bool on) prefs.showResultsAsTable = on; restable->setVisible(on); reslist->setVisible(!on); + if (!on) { + displayingTable = false; + int docnum = restable->getDetailDocNumOrTopRow(); + if (docnum >= 0) + reslist->resultPageFor(docnum); + } else { + displayingTable = true; + int docnum = reslist->pageFirstDocNum(); + if (docnum >= 0) { + restable->makeRowVisible(docnum); + } + nextPageAction->setEnabled(false); + prevPageAction->setEnabled(false); + firstPageAction->setEnabled(false); + } } void RclMain::on_actionSortByDateAsc_toggled(bool on) @@ -1313,7 +1328,6 @@ void RclMain::eraseDocHistory() } } - void RclMain::eraseSearchHistory() { prefs.ssearchHistory.clear(); @@ -1336,13 +1350,16 @@ void RclMain::setUIPrefs() void RclMain::enableNextPage(bool yesno) { - nextPageAction->setEnabled(yesno); + if (!displayingTable) + nextPageAction->setEnabled(yesno); } void RclMain::enablePrevPage(bool yesno) { - prevPageAction->setEnabled(yesno); - firstPageAction->setEnabled(yesno); + if (!displayingTable) { + prevPageAction->setEnabled(yesno); + firstPageAction->setEnabled(yesno); + } } QString RclMain::getQueryDescription() diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index c62d9f55..2bda5644 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -122,6 +122,7 @@ private: SpellW *spellform; QTimer *periodictimer; ResTable *restable; + bool displayingTable; vector m_viewers; map m_stemLangToId; diff --git a/src/qtgui/restable.cpp b/src/qtgui/restable.cpp index 05422608..51f1ca8d 100644 --- a/src/qtgui/restable.cpp +++ b/src/qtgui/restable.cpp @@ -493,6 +493,24 @@ void ResTable::init() splitter->setOrientation(Qt::Vertical); } +int ResTable::getDetailDocNumOrTopRow() +{ + if (m_detaildocnum >= 0) + return m_detaildocnum; + QModelIndex modelIndex = tableView->indexAt(QPoint(0, 0)); + return modelIndex.row(); +} + +void ResTable::makeRowVisible(int row) +{ + LOGDEB(("ResTable::showRow(%d)\n", row)); + QModelIndex modelIndex = m_model->index(row, 0); + tableView->scrollTo(modelIndex, QAbstractItemView::PositionAtTop); + tableView->selectionModel()->clear(); + m_detail->clear(); + m_detaildocnum = -1; + } + // This is called by rclmain_w prior to exiting void ResTable::saveColState() { diff --git a/src/qtgui/restable.h b/src/qtgui/restable.h index 6805ac7b..47e6f7da 100644 --- a/src/qtgui/restable.h +++ b/src/qtgui/restable.h @@ -113,6 +113,8 @@ public: virtual ~ResTable() {} virtual RecollModel *getModel() {return m_model;} virtual ResTableDetailArea* getDetailArea() {return m_detail;} + virtual int getDetailDocNumOrTopRow(); + public slots: virtual void onTableView_currentChanged(const QModelIndex&); virtual void on_tableView_entered(const QModelIndex& index); @@ -135,6 +137,7 @@ public slots: virtual void addColumn(); virtual void resetSort(); // Revert to natural (relevance) order virtual void linkWasClicked(const QUrl&); + virtual void makeRowVisible(int row); signals: void docPreviewClicked(int, Rcl::Doc, int); diff --git a/src/query/reslistpager.cpp b/src/query/reslistpager.cpp index 5a69a0dd..7698c215 100644 --- a/src/query/reslistpager.cpp +++ b/src/query/reslistpager.cpp @@ -91,6 +91,32 @@ void ResListPager::resultPageNext() m_respage = npage; } +void ResListPager::resultPageFor(int docnum) +{ + if (m_docSource.isNull()) { + LOGDEB(("ResListPager::resultPageFor: null source\n")); + return; + } + + int resCnt = m_docSource->getResCnt(); + LOGDEB(("ResListPager::resultPageFor(%d): rescnt %d, winfirst %d\n", + docnum, resCnt, m_winfirst)); + m_winfirst = (docnum / m_pagesize) * m_pagesize; + + // Get the next page of results. + vector npage; + int pagelen = m_docSource->getSeqSlice(m_winfirst, m_pagesize, npage); + + // If page was truncated, there is no next + m_hasNext = (pagelen == m_pagesize); + + if (pagelen <= 0) { + m_winfirst = -1; + return; + } + m_respage = npage; +} + void ResListPager::displayDoc(RclConfig *config, int i, Rcl::Doc& doc, const HiliteData& hdata, const string& sh) diff --git a/src/query/reslistpager.h b/src/query/reslistpager.h index 53a8b8f0..d54811b9 100644 --- a/src/query/reslistpager.h +++ b/src/query/reslistpager.h @@ -82,6 +82,7 @@ public: resultPageNext(); } void resultPageNext(); + void resultPageFor(int docnum); void displayPage(RclConfig *); void displayDoc(RclConfig *, int idx, Rcl::Doc& doc, const HiliteData& hdata, const string& sh = "");