1st version of sorting interface. Needs polishing

This commit is contained in:
dockes 2005-12-02 16:18:20 +00:00
parent f208fe9cc8
commit 868527893c
8 changed files with 388 additions and 220 deletions

View File

@ -333,6 +333,7 @@ class LoadThread : public QThread {
{}
virtual void run()
{
DebugLog::getdbl()->setloglevel(DEBDEB1);
FileInterner interner(filename, rclconfig, tmpdir, mtype);
if (interner.internfile(*out, ipath) != FileInterner::FIDone) {
*statusp = -1;
@ -355,6 +356,7 @@ class ToRichThread : public QThread {
{}
virtual void run()
{
DebugLog::getdbl()->setloglevel(DEBDEB1);
string rich = plaintorich(in, terms, termoffsets);
out = QString::fromUtf8(rich.c_str(), rich.length());
}
@ -416,7 +418,6 @@ void Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc)
doc.mimetype.c_str());
return;
}
LOGDEB(("Load file done\n"));
// Highlight search terms:
progress.setLabelText(tr("Creating preview text"));

View File

@ -8,7 +8,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>631</width>
<width>678</width>
<height>212</height>
</rect>
</property>
@ -22,7 +22,7 @@
</property>
<property name="minimumSize">
<size>
<width>590</width>
<width>678</width>
<height>160</height>
</size>
</property>
@ -99,6 +99,20 @@
<string>Ctrl+S</string>
</property>
</widget>
<widget class="Line">
<property name="name">
<cstring>line4</cstring>
</property>
<property name="frameShape">
<enum>VLine</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>listPrevPB</cstring>
@ -121,6 +135,17 @@
<string>Next page</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>sortPB</cstring>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Sorting</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer1</cstring>
@ -317,7 +342,7 @@
<sender>advSearchPB</sender>
<signal>clicked()</signal>
<receiver>RecollMain</receiver>
<slot>advSearchPB_clicked()</slot>
<slot>showAdvSearchDialog()</slot>
</connection>
<connection>
<sender>helpAbout_RecollAction</sender>
@ -343,11 +368,19 @@
<receiver>queryText</receiver>
<slot>clear()</slot>
</connection>
<connection>
<sender>sortPB</sender>
<signal>clicked()</signal>
<receiver>RecollMain</receiver>
<slot>showSortDialog()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in declaration">sortseq.h</include>
<include location="local" impldecl="in declaration">preview.h</include>
<include location="local" impldecl="in declaration">recoll.h</include>
<include location="local" impldecl="in declaration">advsearch.h</include>
<include location="local" impldecl="in declaration">sort.h</include>
<include location="local" impldecl="in implementation">recollmain.ui.h</include>
</includes>
<variables>
@ -363,6 +396,9 @@
<variable>std::string stemlang;</variable>
<variable>Preview *curPreview;</variable>
<variable>advsearch *asearchform;</variable>
<variable>SortForm *sortform;</variable>
<variable>int sortwidth;</variable>
<variable>RclSortSpec sortspecs;</variable>
<variable>DocSequence *docsource;</variable>
</variables>
<slots>
@ -378,11 +414,13 @@
<slot>listPrevPB_clicked()</slot>
<slot>listNextPB_clicked()</slot>
<slot>previewClosed( Preview * w )</slot>
<slot>advSearchPB_clicked()</slot>
<slot>showAdvSearchDialog()</slot>
<slot>showSortDialog()</slot>
<slot>startAdvSearch( Rcl::AdvSearchData sdata )</slot>
<slot>showAboutDialog()</slot>
<slot>showDocHistory()</slot>
<slot>searchTextChanged( const QString &amp; text )</slot>
<slot>sortDataChanged(int cnt, RclSortSpec spec)</slot>
</slots>
<functions>
<function access="private">init()</function>

View File

@ -62,7 +62,9 @@ void RecollMain::init()
dostem = false;
curPreview = 0;
asearchform = 0;
sortform = 0;
docsource = 0;
sortwidth = 0;
reslistTE->viewport()->installEventFilter(this);
}
@ -386,14 +388,13 @@ void RecollMain::queryText_returnPressed()
if (docsource)
delete docsource;
#if TRYSORT
DocSequenceDb myseq(rcldb);
RclSortSpec ss;
ss.addCrit(RclSortSpec::RCLFLD_MTIME, false);
docsource = new DocSeqSorted(myseq, 10000, ss);
#else
docsource = new DocSequenceDb(rcldb);
#endif
if (sortwidth > 0) {
DocSequenceDb myseq(rcldb);
docsource = new DocSeqSorted(myseq, sortwidth, sortspecs);
} else {
docsource = new DocSequenceDb(rcldb);
}
listNextPB_clicked();
}
@ -570,7 +571,7 @@ void RecollMain::previewClosed(Preview *w)
}
// Open advanced search dialog.
void RecollMain::advSearchPB_clicked()
void RecollMain::showAdvSearchDialog()
{
if (asearchform == 0) {
asearchform = new advsearch(0, tr("Advanced search"), FALSE,
@ -585,6 +586,22 @@ void RecollMain::advSearchPB_clicked()
}
}
void RecollMain::showSortDialog()
{
if (sortform == 0) {
sortform = new SortForm(0, tr("Sort criteria"), FALSE,
WStyle_Customize | WStyle_NormalBorder |
WStyle_Title | WStyle_SysMenu);
sortform->setSizeGripEnabled(FALSE);
connect(sortform, SIGNAL(sortDataChanged(int, RclSortSpec)),
this, SLOT(sortDataChanged(int, RclSortSpec)));
sortform->show();
} else {
sortform->show();
}
}
// Execute an advanced search query. The parameters normally come from
// the advanced search dialog
void RecollMain::startAdvSearch(Rcl::AdvSearchData sdata)
@ -608,14 +625,14 @@ void RecollMain::startAdvSearch(Rcl::AdvSearchData sdata)
curPreview = 0;
if (docsource)
delete docsource;
#if TRYSORT
DocSequenceDb myseq(rcldb);
RclSortSpec ss;
ss.addCrit(RclSortSpec::RCLFLD_MTIME, true);
docsource = new DocSeqSorted(myseq, 10000, ss);
#else
docsource = new DocSequenceDb(rcldb);
#endif
if (sortwidth > 0) {
DocSequenceDb myseq(rcldb);
docsource = new DocSeqSorted(myseq, sortwidth, sortspecs);
} else {
docsource = new DocSequenceDb(rcldb);
}
listNextPB_clicked();
}
@ -705,3 +722,10 @@ void RecollMain::searchTextChanged(const QString & text)
}
}
void RecollMain::sortDataChanged(int cnt, RclSortSpec spec)
{
LOGDEB(("RecollMain::sortDataChanged\n"));
sortwidth = cnt;
sortspecs = spec;
}

View File

@ -1,197 +1,227 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>sort</class>
<class>SortForm</class>
<widget class="QDialog">
<property name="name">
<cstring>sort</cstring>
<cstring>SortForm</cstring>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>163</height>
<width>351</width>
<height>154</height>
</rect>
</property>
<property name="caption">
<string>Form1</string>
<string>Sort Criteria</string>
</property>
<widget class="QLayoutWidget">
<vbox>
<property name="name">
<cstring>layout2</cstring>
<cstring>unnamed</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>12</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<widget class="QLayoutWidget">
<property name="name">
<cstring>unnamed</cstring>
<cstring>layout10</cstring>
</property>
<widget class="QLabel">
<vbox>
<property name="name">
<cstring>textLabel1</cstring>
<cstring>unnamed</cstring>
</property>
<property name="frameShape">
<enum>NoFrame</enum>
</property>
<property name="frameShadow">
<enum>Plain</enum>
</property>
<property name="text">
<string>Sort at most the </string>
</property>
</widget>
<widget class="QSpinBox">
<property name="name">
<cstring>mcntSB</cstring>
</property>
<property name="maxValue">
<number>10000</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>most relevant results by:</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>41</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB1</cstring>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB1</cstring>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout6</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>70</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB2</cstring>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB2</cstring>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout10</cstring>
</property>
<property name="geometry">
<rect>
<x>12</x>
<y>99</y>
<width>336</width>
<height>23</height>
</rect>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB3</cstring>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB3</cstring>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB4</cstring>
</property>
<property name="geometry">
<rect>
<x>183</x>
<y>130</y>
<width>164</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB4</cstring>
</property>
<property name="geometry">
<rect>
<x>13</x>
<y>129</y>
<width>164</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout9</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QCheckBox">
<property name="name">
<cstring>sortCB</cstring>
</property>
<property name="text">
<string>Sort the</string>
</property>
</widget>
<widget class="QSpinBox">
<property name="name">
<cstring>mcntSB</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="maxValue">
<number>10000</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
<widget class="QLabel">
<property name="name">
<cstring>textLabel2</cstring>
</property>
<property name="text">
<string>most relevant results by:</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout3</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB1</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB1</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout6</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QComboBox">
<property name="name">
<cstring>fldCMB2</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>descCB2</cstring>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Descending</string>
</property>
</widget>
</hbox>
</widget>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout7</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QPushButton">
<property name="name">
<cstring>resetPB</cstring>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>closePB</cstring>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>resetPB</sender>
<signal>clicked()</signal>
<receiver>SortForm</receiver>
<slot>reset()</slot>
</connection>
<connection>
<sender>closePB</sender>
<signal>clicked()</signal>
<receiver>SortForm</receiver>
<slot>close()</slot>
</connection>
<connection>
<sender>mcntSB</sender>
<signal>valueChanged(int)</signal>
<receiver>SortForm</receiver>
<slot>setData()</slot>
</connection>
<connection>
<sender>fldCMB1</sender>
<signal>activated(const QString&amp;)</signal>
<receiver>SortForm</receiver>
<slot>setData()</slot>
</connection>
<connection>
<sender>fldCMB2</sender>
<signal>activated(const QString&amp;)</signal>
<receiver>SortForm</receiver>
<slot>setData()</slot>
</connection>
<connection>
<sender>descCB1</sender>
<signal>stateChanged(int)</signal>
<receiver>SortForm</receiver>
<slot>setData()</slot>
</connection>
<connection>
<sender>descCB2</sender>
<signal>stateChanged(int)</signal>
<receiver>SortForm</receiver>
<slot>setData()</slot>
</connection>
<connection>
<sender>sortCB</sender>
<signal>toggled(bool)</signal>
<receiver>SortForm</receiver>
<slot>setData()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in declaration">sortseq.h</include>
<include location="local" impldecl="in implementation">sort.ui.h</include>
</includes>
<signals>
<signal>sortDataChanged(int, RclSortSpec)</signal>
</signals>
<slots>
<slot>reset()</slot>
<slot>setData()</slot>
</slots>
<functions>
<function>init()</function>
</functions>

View File

@ -10,10 +10,66 @@
** destructor.
*****************************************************************************/
#include "sortseq.h"
#include "debuglog.h"
void sort::init()
void SortForm::init()
{
const char *labels[5];
labels[0] = "";
labels[1] = "Date";
labels[2] = "Mime type";
labels[3] = 0;
fldCMB1->insertStrList(labels, 3);
fldCMB1->setCurrentItem(0);
fldCMB2->insertStrList(labels, 3);
fldCMB2->setCurrentItem(0);
}
void SortForm::reset()
{
mcntSB->setValue(100);
fldCMB1->setCurrentItem(0);
fldCMB2->setCurrentItem(0);
descCB1->setChecked(false);
descCB1->setChecked(false);
}
void SortForm::setData()
{
LOGDEB(("SortForm::setData\n"));
RclSortSpec spec;
int width;
mcntSB->setEnabled(sortCB->isChecked());
fldCMB1->setEnabled(sortCB->isChecked());
descCB1->setEnabled(sortCB->isChecked());
fldCMB2->setEnabled(sortCB->isChecked());
descCB2->setEnabled(sortCB->isChecked());
if (!sortCB->isChecked()) {
width = 0;
} else {
bool desc = descCB1->isChecked();
switch (fldCMB1->currentItem()) {
case 1:
spec.addCrit(RclSortSpec::RCLFLD_MTIME, desc?true:false);
break;
case 2:
spec.addCrit(RclSortSpec::RCLFLD_MIMETYPE, desc?true:false);
break;
}
desc = descCB2->isChecked();
switch (fldCMB2->currentItem()) {
case 1:
spec.addCrit(RclSortSpec::RCLFLD_MTIME, desc?true:false);
break;
case 2:
spec.addCrit(RclSortSpec::RCLFLD_MIMETYPE, desc?true:false);
break;
}
width = mcntSB->value();
}
emit sortDataChanged(width, spec);
}

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.2 2005-12-02 14:18:44 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.3 2005-12-02 16:18:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#include <algorithm>
@ -13,38 +13,51 @@ class CompareDocs {
public:
CompareDocs(const RclSortSpec &sortspec) : ss(sortspec) {}
int operator()(const Rcl::Doc &x, const Rcl::Doc &y)
// It's not too clear in the std::sort doc what this should do. This
// behaves as operator<
int operator()(const Rcl::Doc *x, const Rcl::Doc *y)
{
LOGDEB(("Comparing .. \n"));
LOGDEB1(("Comparing .. \n"));
// Compare using each criterion in term. Further comparisons must only
// be made if previous order ones are equal.
for (unsigned int i = 0; i < ss.crits.size(); i++) {
switch (ss.crits[i]) {
case RclSortSpec::RCLFLD_MTIME:
{
LOGDEB((" MTIME\n"));
long xmtime = x.dmtime.empty() ? atol(x.fmtime.c_str()) :
atol(x.dmtime.c_str());
long ymtime = y.dmtime.empty() ? atol(y.fmtime.c_str()) :
atol(y.dmtime.c_str());
long xmtime = x->dmtime.empty() ? atol(x->fmtime.c_str()) :
atol(x->dmtime.c_str());
long ymtime = y->dmtime.empty() ? atol(y->fmtime.c_str()) :
atol(y->dmtime.c_str());
LOGDEB1((" MTIME %ld %ld\n", xmtime, ymtime));
if (ss.dirs[i] ? xmtime > ymtime : xmtime < ymtime)
return 1;
else if (xmtime != ymtime)
return 0;
}
break;
case RclSortSpec::RCLFLD_URL:
LOGDEB((" URL\n"));
if (ss.dirs[i] ? x.url > y.url : x.url < y.url)
LOGDEB1((" URL\n"));
if (ss.dirs[i] ? x->url > y->url : x->url < y->url)
return 1;
else if (x->url != y->url)
return 0;
break;
case RclSortSpec::RCLFLD_IPATH:
LOGDEB((" IPATH\n"));
if (ss.dirs[i] ? x.ipath > y.ipath : x.ipath < y.ipath)
LOGDEB1((" IPATH\n"));
if (ss.dirs[i] ? x->ipath > y->ipath : x->ipath < y->ipath)
return 1;
else if (x->ipath != y->ipath)
return 0;
break;
case RclSortSpec::RCLFLD_MIMETYPE:
LOGDEB((" MIMETYPE\n"));
if (ss.dirs[i] ? x.mimetype > y.mimetype :
x.mimetype < y.mimetype)
LOGDEB1((" MIMETYPE\n"));
if (ss.dirs[i] ? x->mimetype > y->mimetype :
x->mimetype < y->mimetype)
return 1;
else if (x->mimetype != y->mimetype)
return 0;
break;
}
}
@ -58,21 +71,25 @@ DocSeqSorted::DocSeqSorted(DocSequence &iseq, int cnt, RclSortSpec &sortspec)
LOGDEB(("DocSeqSorted:: count %d\n", cnt));
m_docs.resize(cnt);
m_pcs.resize(cnt);
int i;
for (i = 0; i < cnt; i++) {
if (!iseq.getDoc(i, m_docs[i], &m_pcs[i])) {
int percent;
if (!iseq.getDoc(i, m_docs[i], &percent)) {
LOGERR(("DocSeqSorted: getDoc failed for doc %d\n", i));
break;
}
m_docs[i].pc = percent;
}
m_count = i;
LOGDEB(("DocSeqSorted:: m_count %d\n", m_count));
m_docs.resize(m_count);
m_pcs.resize(m_count);
m_docsp.resize(m_count);
for (i = 0; i < m_count; i++)
m_docsp[i] = &m_docs[i];
m_title = string("Sorted ") + iseq.title();
CompareDocs cmp(sortspec);
sort(m_docs.begin(), m_docs.end(), cmp);
sort(m_docsp.begin(), m_docsp.end(), cmp);
}
bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *)
@ -82,7 +99,7 @@ bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *)
if (num >= m_count)
return false;
if (percent)
*percent = m_pcs[num];
doc = m_docs[num];
*percent = (*m_docsp[num]).pc;
doc = *m_docsp[num];
return true;
}

View File

@ -1,6 +1,6 @@
#ifndef _SORTSEQ_H_INCLUDED_
#define _SORTSEQ_H_INCLUDED_
/* @(#$Id: sortseq.h,v 1.1 2005-12-01 16:23:09 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: sortseq.h,v 1.2 2005-12-02 16:18:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include <vector>
#include <string>
@ -33,7 +33,7 @@ class DocSeqSorted : public DocSequence {
std::string m_title;
int m_count;
std::vector<Rcl::Doc> m_docs;
std::vector<int> m_pcs;
std::vector<Rcl::Doc *> m_docsp;
};
#endif /* _SORTSEQ_H_INCLUDED_ */

View File

@ -1,6 +1,6 @@
#ifndef _DB_H_INCLUDED_
#define _DB_H_INCLUDED_
/* @(#$Id: rcldb.h,v 1.19 2005-11-25 09:12:26 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: rcldb.h,v 1.20 2005-12-02 16:18:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
@ -48,6 +48,8 @@ class Doc {
string text;
int pc; // used by sortseq, convenience
void erase() {
url.erase();
ipath.erase();