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>
<addaction name="fileToggleIndexingAction"/>
<addaction name="separator"/>
<addaction name="fileEraseSearchHistoryAction"/>
<addaction name="fileEraseDocHistoryAction"/>
<addaction name="showMissingHelpers_Action"/>
<addaction name="separator"/>
@ -204,6 +205,14 @@
<cstring>fileEraseDocHistoryAction</cstring>
</property>
</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">
<property name="text">
<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("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());
curPreview = 0;
asearchform = 0;
@ -225,6 +225,8 @@ void RclMain::init()
this, SLOT(toggleIndexing()));
connect(fileEraseDocHistoryAction, SIGNAL(activated()),
this, SLOT(eraseDocHistory()));
connect(fileEraseSearchHistoryAction, SIGNAL(activated()),
this, SLOT(eraseSearchHistory()));
connect(helpAbout_RecollAction, SIGNAL(activated()),
this, SLOT(showAboutDialog()));
connect(showMissingHelpers_Action, SIGNAL(activated()),
@ -262,7 +264,7 @@ void RclMain::init()
connect(this, SIGNAL(sortDataChanged(DocSeqSortSpec)),
restable, SLOT(onSortDataChanged(DocSeqSortSpec)));
connect(restable->getModel(), SIGNAL(sortDataChanged(DocSeqSortSpec)),
connect(restable->getModel(), SIGNAL(sortColumnChanged(DocSeqSortSpec)),
this, SLOT(onResTableSortBy(DocSeqSortSpec)));
connect(restable, SIGNAL(docEditClicked(Rcl::Doc)),
this, SLOT(startNativeViewer(Rcl::Doc)));
@ -605,6 +607,9 @@ void RclMain::startSearch(RefCntr<Rcl::SearchData> sdata)
src->setAbstractParams(prefs.queryBuildAbstract,
prefs.queryReplaceAbstract);
m_source = RefCntr<DocSequence>(src);
m_source->setSortSpec(m_sortspec);
m_source->setFiltSpec(m_filtspec);
emit docSourceChanged(m_source);
emit sortDataChanged(m_sortspec);
emit filtDataChanged(m_filtspec);
@ -881,6 +886,7 @@ void RclMain::onSortCtlChanged()
prefs.sortActive = prefs.sortDesc = false;
}
LOGDEB(("RclMain::onCtlDataChanged(): emitting change signals\n"));
m_source->setSortSpec(m_sortspec);
emit sortDataChanged(m_sortspec);
emit applyFiltSortData();
}
@ -904,13 +910,8 @@ void RclMain::on_actionShowResultsAsTable_toggled(bool on)
{
LOGDEB(("RclMain::on_actionShowResultsAsTable_toggled(%d)\n", int(on)));
prefs.showResultsAsTable = on;
if (on) {
restable->show();
reslist->hide();
} else {
restable->hide();
reslist->show();
}
restable->setVisible(on);
reslist->setVisible(!on);
}
void RclMain::on_actionSortByDateAsc_toggled(bool on)
@ -1259,6 +1260,8 @@ void RclMain::showDocHistory()
string(tr("Document history").toUtf8()));
src->setDescription((const char *)tr("History data").toUtf8());
m_source = RefCntr<DocSequence>(src);
m_source->setSortSpec(m_sortspec);
m_source->setFiltSpec(m_filtspec);
emit docSourceChanged(m_source);
emit sortDataChanged(m_sortspec);
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
void RclMain::setUIPrefs()
{
@ -1338,6 +1348,7 @@ void RclMain::catgFilter(int id)
it != tps.end(); it++)
m_filtspec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
}
m_source->setFiltSpec(m_filtspec);
emit filtDataChanged(m_filtspec);
emit applyFiltSortData();
}

View File

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

View File

@ -268,16 +268,17 @@ extern "C" int XFlush(void *);
void ResList::setDocSource(RefCntr<DocSequence> nsource)
{
LOGDEB(("ResList::setDocSource()\n"));
m_source = RefCntr<DocSequence>(new DocSource(nsource));
}
// Reapply parameters. Sort params probably changed
void ResList::readDocSource()
{
LOGDEB(("ResList::readDocSource\n"));
LOGDEB(("ResList::readDocSource()\n"));
resetView();
if (m_source.isNull())
return;
resetList();
m_listId = newListId();
// Reset the page size in case the preference was changed
@ -287,19 +288,24 @@ void ResList::readDocSource()
emit hasResults(m_source->getResCnt());
}
void ResList::setSortParams(DocSeqSortSpec spec)
void ResList::setSortParams(DocSeqSortSpec)
{
LOGDEB(("ResList::setSortParams\n"));
m_source->setSortSpec(spec);
LOGDEB2(("ResList::setSortParams\n"));
}
void ResList::setFilterParams(const DocSeqFiltSpec& spec)
void ResList::setFilterParams(const DocSeqFiltSpec&)
{
LOGDEB(("ResList::setFilterParams\n"));
m_source->setFiltSpec(spec);
LOGDEB2(("ResList::setFilterParams\n"));
}
void ResList::resetList()
{
LOGDEB(("ResList::resetList()\n"));
setDocSource(RefCntr<DocSequence>());
resetView();
}
void ResList::resetView()
{
m_curPvDoc = -1;
// 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);
};
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
{
LOGDEB2(("RecollModel::data: row %d col %d\n", index.row(),
index.column()));
LOGDEB1(("RecollModel::data: row %d col %d\n", index.row(),
index.column()));
if (m_source.isNull() || role != Qt::DisplayRole || !index.isValid() ||
index.column() >= int(m_fields.size())) {
return QVariant();
@ -285,7 +285,7 @@ void RecollModel::sort(int column, Qt::SortOrder order)
spec.desc = order == Qt::AscendingOrder ? false : true;
m_source->setSortSpec(spec);
readDocSource();
emit sortDataChanged(spec);
emit sortColumnChanged(spec);
}
}
@ -444,6 +444,7 @@ void ResTable::onSortDataChanged(DocSeqSortSpec)
void ResTable::readDocSource(bool resetPos)
{
LOGDEB(("ResTable::readDocSource(%d)\n", int(resetPos)));
if (resetPos)
tableView->verticalScrollBar()->setSliderPosition(0);

View File

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

View File

@ -45,6 +45,10 @@ void SSearch::init()
searchTypCMB->addItem(tr("File name"));
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->setEditText("");
connect(queryText->lineEdit(), SIGNAL(returnPressed()),
@ -191,13 +195,11 @@ void SSearch::startSimpleSearch()
// So do it by hand.
QString txt = queryText->currentText();
int index = queryText->findText(txt);
if (index > 0)
if (index >= 0)
queryText->removeItem(index);
// The combobox is set for no insertion, insert here:
queryText->insertItem(0, txt);
queryText->setCurrentIndex(0);
// Save the current state of the listbox list to the prefs (will
// go to disk)
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 "debuglog.h"
string DocSequence::o_sort_trans;
string DocSequence::o_filt_trans;
int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
{
int ret = 0;
@ -78,11 +81,10 @@ bool DocSource::buildStack()
return true;
}
string DocSource::o_sort_trans;
string DocSource::o_filt_trans;
string DocSource::title()
{
if (m_seq.isNull())
return "";
string qual;
if (m_fspec.isNotNull() && !m_sspec.isNotNull())
qual = string(" (") + o_filt_trans + string(")");

View File

@ -131,6 +131,14 @@ class DocSequence {
virtual bool setSortSpec(const DocSeqSortSpec &) {return false;}
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:
string m_title;
};
@ -147,20 +155,28 @@ public:
virtual string getAbstract(Rcl::Doc& doc)
{
if (m_seq.isNull())
return "";
return m_seq->getAbstract(doc);
}
virtual string getDescription()
{
if (m_seq.isNull())
return "";
return m_seq->getDescription();
}
virtual bool getTerms(vector<string>& terms,
vector<vector<string> >& groups,
vector<int>& gslks)
{
if (m_seq.isNull())
return false;
return m_seq->getTerms(terms, groups, gslks);
}
virtual void getUTerms(vector<string>& terms)
{
if (m_seq.isNull())
return;
m_seq->getUTerms(terms);
}
virtual string title() {return m_seq->title();}
@ -183,25 +199,22 @@ public:
virtual bool setSortSpec(const DocSeqSortSpec &);
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0)
{
if (m_seq.isNull())
return false;
return m_seq->getDoc(num, doc, sh);
}
virtual int getResCnt()
{
if (m_seq.isNull())
return 0;
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();
private:
bool buildStack();
void stripStack();
DocSeqFiltSpec m_fspec;
DocSeqSortSpec m_sspec;
static string o_sort_trans;
static string o_filt_trans;
};
#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),
m_rescnt(-1),
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)
{
setQuery();
if (sh) sh->erase();
return m_q->getDoc(num, doc);
}
int DocSequenceDb::getResCnt()
{
setQuery();
if (m_rescnt < 0) {
m_rescnt= m_q->getResCnt();
}
@ -71,6 +76,7 @@ int DocSequenceDb::getResCnt()
string DocSequenceDb::getAbstract(Rcl::Doc &doc)
{
setQuery();
if (!m_q->whatDb())
return doc.meta[Rcl::Doc::keyabs];
string abstract;
@ -86,6 +92,7 @@ string DocSequenceDb::getAbstract(Rcl::Doc &doc)
bool DocSequenceDb::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
{
setQuery();
string udi;
if (!FileInterner::getEnclosing(doc.url, doc.ipath, pdoc.url, pdoc.ipath,
udi))
@ -95,9 +102,22 @@ bool DocSequenceDb::getEnclosing(Rcl::Doc& doc, Rcl::Doc& pdoc)
list<string> DocSequenceDb::expand(Rcl::Doc &doc)
{
setQuery();
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)
{
LOGDEB(("DocSequenceDb::setFiltSpec\n"));
@ -114,10 +134,13 @@ bool DocSequenceDb::setFiltSpec(const DocSeqFiltSpec &fs)
m_fsdata->addFiletype(fs.values[i]);
}
}
m_isFiltered = true;
} else {
m_fsdata = m_sdata;
m_isFiltered = false;
}
return m_q->setQuery(m_fsdata);
m_needSetQuery = true;
return true;
}
bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &spec)
@ -126,13 +149,20 @@ bool DocSequenceDb::setSortSpec(const DocSeqSortSpec &spec)
spec.field.c_str(), spec.desc ? "desc" : "asc"));
if (spec.isNotNull()) {
m_q->setSortBy(spec.field, !spec.desc);
m_isSorted = true;
} else {
m_q->setSortBy(string(), true);
m_isSorted = false;
}
return m_q->setQuery(m_fsdata);
m_needSetQuery = true;
return true;
}
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 "rclquery.h"
/** A DocSequence from a Db query (there should be one active for this
to make sense) */
/** A DocSequence from a Db query */
class DocSequenceDb : public DocSequence {
public:
DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
@ -44,12 +43,12 @@ class DocSequenceDb : public DocSequence {
virtual bool setFiltSpec(const DocSeqFiltSpec &filtspec);
virtual bool canSort() {return true;}
virtual bool setSortSpec(const DocSeqSortSpec &sortspec);
virtual bool setQuery();
virtual void setAbstractParams(bool qba, bool qra)
{
m_queryBuildAbstract = qba;
m_queryReplaceAbstract = qra;
}
virtual string title();
private:
RefCntr<Rcl::Query> m_q;
@ -58,6 +57,10 @@ class DocSequenceDb : public DocSequence {
int m_rescnt;
bool m_queryBuildAbstract;
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_ */