qtgui: add menu to erase search history + misc cleanups

This commit is contained in:
Jean-Francois Dockes 2011-01-15 15:39:15 +01:00
parent 85b36d3c34
commit c4f79e49da
12 changed files with 120 additions and 41 deletions

View File

@ -136,6 +136,7 @@
</property> </property>
<addaction name="fileToggleIndexingAction"/> <addaction name="fileToggleIndexingAction"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="fileEraseSearchHistoryAction"/>
<addaction name="fileEraseDocHistoryAction"/> <addaction name="fileEraseDocHistoryAction"/>
<addaction name="showMissingHelpers_Action"/> <addaction name="showMissingHelpers_Action"/>
<addaction name="separator"/> <addaction name="separator"/>
@ -204,6 +205,14 @@
<cstring>fileEraseDocHistoryAction</cstring> <cstring>fileEraseDocHistoryAction</cstring>
</property> </property>
</action> </action>
<action name="fileEraseSearchHistoryAction">
<property name="text">
<string>&amp;Erase search history</string>
</property>
<property name="name" stdset="0">
<cstring>fileEraseSearchHistoryAction</cstring>
</property>
</action>
<action name="showMissingHelpers_Action"> <action name="showMissingHelpers_Action">
<property name="text"> <property name="text">
<string>&amp;Show missing helpers</string> <string>&amp;Show missing helpers</string>

View File

@ -91,7 +91,7 @@ void RclMain::init()
QT_TR_NOOP("spreadsheet"), QT_TR_NOOP("text"), QT_TR_NOOP("spreadsheet"), QT_TR_NOOP("text"),
QT_TR_NOOP("sorted"), QT_TR_NOOP("filtered") QT_TR_NOOP("sorted"), QT_TR_NOOP("filtered")
}; };
DocSource::set_translations((const char *)tr("sorted").toUtf8(), DocSequence::set_translations((const char *)tr("sorted").toUtf8(),
(const char *)tr("filtered").toUtf8()); (const char *)tr("filtered").toUtf8());
curPreview = 0; curPreview = 0;
asearchform = 0; asearchform = 0;
@ -225,6 +225,8 @@ void RclMain::init()
this, SLOT(toggleIndexing())); this, SLOT(toggleIndexing()));
connect(fileEraseDocHistoryAction, SIGNAL(activated()), connect(fileEraseDocHistoryAction, SIGNAL(activated()),
this, SLOT(eraseDocHistory())); this, SLOT(eraseDocHistory()));
connect(fileEraseSearchHistoryAction, SIGNAL(activated()),
this, SLOT(eraseSearchHistory()));
connect(helpAbout_RecollAction, SIGNAL(activated()), connect(helpAbout_RecollAction, SIGNAL(activated()),
this, SLOT(showAboutDialog())); this, SLOT(showAboutDialog()));
connect(showMissingHelpers_Action, SIGNAL(activated()), connect(showMissingHelpers_Action, SIGNAL(activated()),
@ -262,7 +264,7 @@ void RclMain::init()
connect(this, SIGNAL(sortDataChanged(DocSeqSortSpec)), connect(this, SIGNAL(sortDataChanged(DocSeqSortSpec)),
restable, SLOT(onSortDataChanged(DocSeqSortSpec))); restable, SLOT(onSortDataChanged(DocSeqSortSpec)));
connect(restable->getModel(), SIGNAL(sortDataChanged(DocSeqSortSpec)), connect(restable->getModel(), SIGNAL(sortColumnChanged(DocSeqSortSpec)),
this, SLOT(onResTableSortBy(DocSeqSortSpec))); this, SLOT(onResTableSortBy(DocSeqSortSpec)));
connect(restable, SIGNAL(docEditClicked(Rcl::Doc)), connect(restable, SIGNAL(docEditClicked(Rcl::Doc)),
this, SLOT(startNativeViewer(Rcl::Doc))); this, SLOT(startNativeViewer(Rcl::Doc)));
@ -605,6 +607,9 @@ void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata)
src->setAbstractParams(prefs.queryBuildAbstract, src->setAbstractParams(prefs.queryBuildAbstract,
prefs.queryReplaceAbstract); prefs.queryReplaceAbstract);
m_source = RefCntr<DocSequence>(src); m_source = RefCntr<DocSequence>(src);
m_source->setSortSpec(m_sortspec);
m_source->setFiltSpec(m_filtspec);
emit docSourceChanged(m_source); emit docSourceChanged(m_source);
emit sortDataChanged(m_sortspec); emit sortDataChanged(m_sortspec);
emit filtDataChanged(m_filtspec); emit filtDataChanged(m_filtspec);
@ -881,6 +886,7 @@ void RclMain::onSortCtlChanged()
prefs.sortActive = prefs.sortDesc = false; prefs.sortActive = prefs.sortDesc = false;
} }
LOGDEB(("RclMain::onCtlDataChanged(): emitting change signals\n")); LOGDEB(("RclMain::onCtlDataChanged(): emitting change signals\n"));
m_source->setSortSpec(m_sortspec);
emit sortDataChanged(m_sortspec); emit sortDataChanged(m_sortspec);
emit applyFiltSortData(); emit applyFiltSortData();
} }
@ -904,13 +910,8 @@ void RclMain::on_actionShowResultsAsTable_toggled(bool on)
{ {
LOGDEB(("RclMain::on_actionShowResultsAsTable_toggled(%d)\n", int(on))); LOGDEB(("RclMain::on_actionShowResultsAsTable_toggled(%d)\n", int(on)));
prefs.showResultsAsTable = on; prefs.showResultsAsTable = on;
if (on) { restable->setVisible(on);
restable->show(); reslist->setVisible(!on);
reslist->hide();
} else {
restable->hide();
reslist->show();
}
} }
void RclMain::on_actionSortByDateAsc_toggled(bool on) void RclMain::on_actionSortByDateAsc_toggled(bool on)
@ -1259,6 +1260,8 @@ void RclMain::showDocHistory()
string(tr("Document history").toUtf8())); string(tr("Document history").toUtf8()));
src->setDescription((const char *)tr("History data").toUtf8()); src->setDescription((const char *)tr("History data").toUtf8());
m_source = RefCntr<DocSequence>(src); m_source = RefCntr<DocSequence>(src);
m_source->setSortSpec(m_sortspec);
m_source->setFiltSpec(m_filtspec);
emit docSourceChanged(m_source); emit docSourceChanged(m_source);
emit sortDataChanged(m_sortspec); emit sortDataChanged(m_sortspec);
emit filtDataChanged(m_filtspec); emit filtDataChanged(m_filtspec);
@ -1277,6 +1280,13 @@ void RclMain::eraseDocHistory()
} }
} }
void RclMain::eraseSearchHistory()
{
prefs.ssearchHistory.clear();
sSearch->queryText->clear();
}
// Called when the uiprefs dialog is ok'd // Called when the uiprefs dialog is ok'd
void RclMain::setUIPrefs() void RclMain::setUIPrefs()
{ {
@ -1338,6 +1348,7 @@ void RclMain::catgFilter(int id)
it != tps.end(); it++) it != tps.end(); it++)
m_filtspec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it); m_filtspec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
} }
m_source->setFiltSpec(m_filtspec);
emit filtDataChanged(m_filtspec); emit filtDataChanged(m_filtspec);
emit applyFiltSortData(); emit applyFiltSortData();
} }

View File

@ -87,6 +87,7 @@ public slots:
virtual void previewExposed(Preview *, int sid, int docnum); virtual void previewExposed(Preview *, int sid, int docnum);
virtual void resetSearch(); virtual void resetSearch();
virtual void eraseDocHistory(); virtual void eraseDocHistory();
virtual void eraseSearchHistory();
virtual void setStemLang(QAction *id); virtual void setStemLang(QAction *id);
virtual void adjustPrefsMenu(); virtual void adjustPrefsMenu();
virtual void catgFilter(int); virtual void catgFilter(int);

View File

@ -268,16 +268,17 @@ extern "C" int XFlush(void *);
void ResList::setDocSource(RefCntr<DocSequence> nsource) void ResList::setDocSource(RefCntr<DocSequence> nsource)
{ {
LOGDEB(("ResList::setDocSource()\n"));
m_source = RefCntr<DocSequence>(new DocSource(nsource)); m_source = RefCntr<DocSequence>(new DocSource(nsource));
} }
// Reapply parameters. Sort params probably changed // Reapply parameters. Sort params probably changed
void ResList::readDocSource() void ResList::readDocSource()
{ {
LOGDEB(("ResList::readDocSource\n")); LOGDEB(("ResList::readDocSource()\n"));
resetView();
if (m_source.isNull()) if (m_source.isNull())
return; return;
resetList();
m_listId = newListId(); m_listId = newListId();
// Reset the page size in case the preference was changed // Reset the page size in case the preference was changed
@ -287,19 +288,24 @@ void ResList::readDocSource()
emit hasResults(m_source->getResCnt()); emit hasResults(m_source->getResCnt());
} }
void ResList::setSortParams(DocSeqSortSpec spec) void ResList::setSortParams(DocSeqSortSpec)
{ {
LOGDEB(("ResList::setSortParams\n")); LOGDEB2(("ResList::setSortParams\n"));
m_source->setSortSpec(spec);
} }
void ResList::setFilterParams(const DocSeqFiltSpec& spec) void ResList::setFilterParams(const DocSeqFiltSpec&)
{ {
LOGDEB(("ResList::setFilterParams\n")); LOGDEB2(("ResList::setFilterParams\n"));
m_source->setFiltSpec(spec);
} }
void ResList::resetList() void ResList::resetList()
{
LOGDEB(("ResList::resetList()\n"));
setDocSource(RefCntr<DocSequence>());
resetView();
}
void ResList::resetView()
{ {
m_curPvDoc = -1; m_curPvDoc = -1;
// There should be a progress bar for long searches but there isn't // There should be a progress bar for long searches but there isn't

View File

@ -123,6 +123,7 @@ class ResList : public QTextBrowser
emit linkClicked(s, m_lstClckMod); emit linkClicked(s, m_lstClckMod);
}; };
static int newListId(); static int newListId();
void resetView();
}; };

View File

@ -252,8 +252,8 @@ QVariant RecollModel::headerData(int idx, Qt::Orientation orientation,
QVariant RecollModel::data(const QModelIndex& index, int role) const QVariant RecollModel::data(const QModelIndex& index, int role) const
{ {
LOGDEB2(("RecollModel::data: row %d col %d\n", index.row(), LOGDEB1(("RecollModel::data: row %d col %d\n", index.row(),
index.column())); index.column()));
if (m_source.isNull() || role != Qt::DisplayRole || !index.isValid() || if (m_source.isNull() || role != Qt::DisplayRole || !index.isValid() ||
index.column() >= int(m_fields.size())) { index.column() >= int(m_fields.size())) {
return QVariant(); return QVariant();
@ -285,7 +285,7 @@ void RecollModel::sort(int column, Qt::SortOrder order)
spec.desc = order == Qt::AscendingOrder ? false : true; spec.desc = order == Qt::AscendingOrder ? false : true;
m_source->setSortSpec(spec); m_source->setSortSpec(spec);
readDocSource(); readDocSource();
emit sortDataChanged(spec); emit sortColumnChanged(spec);
} }
} }
@ -444,6 +444,7 @@ void ResTable::onSortDataChanged(DocSeqSortSpec)
void ResTable::readDocSource(bool resetPos) void ResTable::readDocSource(bool resetPos)
{ {
LOGDEB(("ResTable::readDocSource(%d)\n", int(resetPos)));
if (resetPos) if (resetPos)
tableView->verticalScrollBar()->setSliderPosition(0); tableView->verticalScrollBar()->setSliderPosition(0);

View File

@ -57,7 +57,7 @@ public:
virtual void addColumn(int, const string&); virtual void addColumn(int, const string&);
signals: signals:
void sortDataChanged(DocSeqSortSpec); void sortColumnChanged(DocSeqSortSpec);
private: private:
mutable RefCntr<DocSequence> m_source; mutable RefCntr<DocSequence> m_source;

View File

@ -45,6 +45,10 @@ void SSearch::init()
searchTypCMB->addItem(tr("File name")); searchTypCMB->addItem(tr("File name"));
searchTypCMB->addItem(tr("Query language")); searchTypCMB->addItem(tr("Query language"));
// We'd like to use QComboBox::InsertAtTop but it doesn't do lru
// (existing item stays at its place instead of jumping at top)
queryText->setInsertPolicy(QComboBox::NoInsert);
queryText->addItems(prefs.ssearchHistory); queryText->addItems(prefs.ssearchHistory);
queryText->setEditText(""); queryText->setEditText("");
connect(queryText->lineEdit(), SIGNAL(returnPressed()), connect(queryText->lineEdit(), SIGNAL(returnPressed()),
@ -191,13 +195,11 @@ void SSearch::startSimpleSearch()
// So do it by hand. // So do it by hand.
QString txt = queryText->currentText(); QString txt = queryText->currentText();
int index = queryText->findText(txt); int index = queryText->findText(txt);
if (index > 0) if (index >= 0)
queryText->removeItem(index); queryText->removeItem(index);
// The combobox is set for no insertion, insert here:
queryText->insertItem(0, txt); queryText->insertItem(0, txt);
queryText->setCurrentIndex(0); queryText->setCurrentIndex(0);
// Save the current state of the listbox list to the prefs (will // Save the current state of the listbox list to the prefs (will
// go to disk) // go to disk)
prefs.ssearchHistory.clear(); prefs.ssearchHistory.clear();

View File

@ -22,6 +22,9 @@ static char rcsid[] = "@(#$Id: docseq.cpp,v 1.11 2008-09-29 08:59:20 dockes Exp
#include "sortseq.h" #include "sortseq.h"
#include "debuglog.h" #include "debuglog.h"
string DocSequence::o_sort_trans;
string DocSequence::o_filt_trans;
int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result) int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
{ {
int ret = 0; int ret = 0;
@ -78,11 +81,10 @@ bool DocSource::buildStack()
return true; return true;
} }
string DocSource::o_sort_trans;
string DocSource::o_filt_trans;
string DocSource::title() string DocSource::title()
{ {
if (m_seq.isNull())
return "";
string qual; string qual;
if (m_fspec.isNotNull() && !m_sspec.isNotNull()) if (m_fspec.isNotNull() && !m_sspec.isNotNull())
qual = string(" (") + o_filt_trans + string(")"); qual = string(" (") + o_filt_trans + string(")");

View File

@ -131,6 +131,14 @@ class DocSequence {
virtual bool setSortSpec(const DocSeqSortSpec &) {return false;} virtual bool setSortSpec(const DocSeqSortSpec &) {return false;}
virtual RefCntr<DocSequence> getSourceSeq() {return RefCntr<DocSequence>();} virtual RefCntr<DocSequence> getSourceSeq() {return RefCntr<DocSequence>();}
static void set_translations(const string& sort, const string& filt)
{
o_sort_trans = sort;
o_filt_trans = filt;
}
protected:
static string o_sort_trans;
static string o_filt_trans;
private: private:
string m_title; string m_title;
}; };
@ -147,20 +155,28 @@ public:
virtual string getAbstract(Rcl::Doc& doc) virtual string getAbstract(Rcl::Doc& doc)
{ {
if (m_seq.isNull())
return "";
return m_seq->getAbstract(doc); return m_seq->getAbstract(doc);
} }
virtual string getDescription() virtual string getDescription()
{ {
if (m_seq.isNull())
return "";
return m_seq->getDescription(); return m_seq->getDescription();
} }
virtual bool getTerms(vector<string>& terms, virtual bool getTerms(vector<string>& terms,
vector<vector<string> >& groups, vector<vector<string> >& groups,
vector<int>& gslks) vector<int>& gslks)
{ {
if (m_seq.isNull())
return false;
return m_seq->getTerms(terms, groups, gslks); return m_seq->getTerms(terms, groups, gslks);
} }
virtual void getUTerms(vector<string>& terms) virtual void getUTerms(vector<string>& terms)
{ {
if (m_seq.isNull())
return;
m_seq->getUTerms(terms); m_seq->getUTerms(terms);
} }
virtual string title() {return m_seq->title();} virtual string title() {return m_seq->title();}
@ -183,25 +199,22 @@ public:
virtual bool setSortSpec(const DocSeqSortSpec &); virtual bool setSortSpec(const DocSeqSortSpec &);
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0) virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0)
{ {
if (m_seq.isNull())
return false;
return m_seq->getDoc(num, doc, sh); return m_seq->getDoc(num, doc, sh);
} }
virtual int getResCnt() virtual int getResCnt()
{ {
if (m_seq.isNull())
return 0;
return m_seq->getResCnt(); return m_seq->getResCnt();
} }
static void set_translations(const string& sort, const string& filt)
{
o_sort_trans = sort;
o_filt_trans = filt;
}
virtual string title(); virtual string title();
private: private:
bool buildStack(); bool buildStack();
void stripStack(); void stripStack();
DocSeqFiltSpec m_fspec; DocSeqFiltSpec m_fspec;
DocSeqSortSpec m_sspec; DocSeqSortSpec m_sspec;
static string o_sort_trans;
static string o_filt_trans;
}; };
#endif /* _DOCSEQ_H_INCLUDED_ */ #endif /* _DOCSEQ_H_INCLUDED_ */

View File

@ -30,7 +30,10 @@ DocSequenceDb::DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
: DocSequence(t), m_q(q), m_sdata(sdata), m_fsdata(sdata), : DocSequence(t), m_q(q), m_sdata(sdata), m_fsdata(sdata),
m_rescnt(-1), m_rescnt(-1),
m_queryBuildAbstract(true), m_queryBuildAbstract(true),
m_queryReplaceAbstract(false) m_queryReplaceAbstract(false),
m_isFiltered(false),
m_isSorted(false),
m_needSetQuery(false)
{ {
} }
@ -57,12 +60,14 @@ string DocSequenceDb::getDescription()
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, string *sh) bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, string *sh)
{ {
setQuery();
if (sh) sh->erase(); if (sh) sh->erase();
return m_q->getDoc(num, doc); return m_q->getDoc(num, doc);
} }
int DocSequenceDb::getResCnt() int DocSequenceDb::getResCnt()
{ {
setQuery();
if (m_rescnt < 0) { if (m_rescnt < 0) {
m_rescnt= m_q->getResCnt(); m_rescnt= m_q->getResCnt();
} }
@ -71,6 +76,7 @@ int DocSequenceDb::getResCnt()
string DocSequenceDb::getAbstract(Rcl::Doc &doc) string DocSequenceDb::getAbstract(Rcl::Doc &doc)
{ {
setQuery();
if (!m_q->whatDb()) if (!m_q->whatDb())
return doc.meta[Rcl::Doc::keyabs]; return doc.meta[Rcl::Doc::keyabs];
string abstract; string abstract;
@ -86,6 +92,7 @@ string DocSequenceDb::getAbstract(Rcl::Doc &doc)
bool DocSequenceDb::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc) bool DocSequenceDb::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
{ {
setQuery();
string udi; string udi;
if (!FileInterner::getEnclosing(doc.url, doc.ipath, pdoc.url, pdoc.ipath, if (!FileInterner::getEnclosing(doc.url, doc.ipath, pdoc.url, pdoc.ipath,
udi)) udi))
@ -95,9 +102,22 @@ bool DocSequenceDb::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
list<string> DocSequenceDb::expand(Rcl::Doc &doc) list<string> DocSequenceDb::expand(Rcl::Doc &doc)
{ {
setQuery();
return m_q->expand(doc); return m_q->expand(doc);
} }
string DocSequenceDb::title()
{
string qual;
if (m_isFiltered && !m_isSorted)
qual = string(" (") + o_filt_trans + string(")");
else if (!m_isFiltered && m_isSorted)
qual = string(" (") + o_sort_trans + string(")");
else if (m_isFiltered && m_isSorted)
qual = string(" (") + o_sort_trans + string(",") + o_filt_trans + string(")");
return DocSequence::title() + qual;
}
bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs) bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
{ {
LOGDEB(("DocSequenceDb::setFiltSpec\n")); LOGDEB(("DocSequenceDb::setFiltSpec\n"));
@ -114,10 +134,13 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
m_fsdata->addFiletype(fs.values[i]); m_fsdata->addFiletype(fs.values[i]);
} }
} }
m_isFiltered = true;
} else { } else {
m_fsdata = m_sdata; m_fsdata = m_sdata;
m_isFiltered = false;
} }
return m_q->setQuery(m_fsdata); m_needSetQuery = true;
return true;
} }
bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &spec) bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &spec)
@ -126,13 +149,20 @@ bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &spec)
spec.field.c_str(), spec.desc ? "desc" : "asc")); spec.field.c_str(), spec.desc ? "desc" : "asc"));
if (spec.isNotNull()) { if (spec.isNotNull()) {
m_q->setSortBy(spec.field, !spec.desc); m_q->setSortBy(spec.field, !spec.desc);
m_isSorted = true;
} else { } else {
m_q->setSortBy(string(), true); m_q->setSortBy(string(), true);
m_isSorted = false;
} }
return m_q->setQuery(m_fsdata); m_needSetQuery = true;
return true;
} }
bool DocSequenceDb::setQuery() bool DocSequenceDb::setQuery()
{ {
return m_q->setQuery(m_fsdata); if (!m_needSetQuery)
return true;
m_rescnt = -1;
m_needSetQuery = !m_q->setQuery(m_fsdata);
return !m_needSetQuery;
} }

View File

@ -23,8 +23,7 @@
#include "searchdata.h" #include "searchdata.h"
#include "rclquery.h" #include "rclquery.h"
/** A DocSequence from a Db query (there should be one active for this /** A DocSequence from a Db query */
to make sense) */
class DocSequenceDb : public DocSequence { class DocSequenceDb : public DocSequence {
public: public:
DocSequenceDb(RefCntr<Rcl::Query> q, const string &t, DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
@ -44,12 +43,12 @@ class DocSequenceDb : public DocSequence {
virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec); virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec);
virtual bool canSort() {return true;} virtual bool canSort() {return true;}
virtual bool setSortSpec(const DocSeqSortSpec &sortspec); virtual bool setSortSpec(const DocSeqSortSpec &sortspec);
virtual bool setQuery();
virtual void setAbstractParams(bool qba, bool qra) virtual void setAbstractParams(bool qba, bool qra)
{ {
m_queryBuildAbstract = qba; m_queryBuildAbstract = qba;
m_queryReplaceAbstract = qra; m_queryReplaceAbstract = qra;
} }
virtual string title();
private: private:
RefCntr<Rcl::Query> m_q; RefCntr<Rcl::Query> m_q;
@ -58,6 +57,10 @@ class DocSequenceDb : public DocSequence {
int m_rescnt; int m_rescnt;
bool m_queryBuildAbstract; bool m_queryBuildAbstract;
bool m_queryReplaceAbstract; bool m_queryReplaceAbstract;
bool m_isFiltered;
bool m_isSorted;
bool m_needSetQuery; // search data changed, need to reapply before fetch
bool setQuery();
}; };
#endif /* _DOCSEQDB_H_INCLUDED_ */ #endif /* _DOCSEQDB_H_INCLUDED_ */