GUI: extend sort state persistence to non-date fields

This commit is contained in:
Jean-Francois Dockes 2011-05-02 08:55:02 +02:00
parent 87dadc42bd
commit 21aa44b39e
6 changed files with 29 additions and 12 deletions

View File

@ -146,12 +146,21 @@ void rwSettings(bool writing)
"english");
SETTING_RW(prefs.useDesktopOpen,
"/Recoll/prefs/useDesktopOpen", Bool, true);
SETTING_RW(prefs.keepSort,
"/Recoll/prefs/keepSort", Bool, false);
SETTING_RW(prefs.sortField, "/Recoll/prefs/sortField", String, "");
SETTING_RW(prefs.sortActive,
"/Recoll/prefs/sortActive", Bool, false);
SETTING_RW(prefs.sortDesc,
"/Recoll/prefs/query/sortDesc", Bool, 0);
if (!writing) {
// Handle transition from older prefs which did not store sortColumn
// (Active always meant sort by date).
if (prefs.sortActive && prefs.sortField.isNull())
prefs.sortField = "mtime";
}
SETTING_RW(prefs.queryBuildAbstract,
"/Recoll/prefs/query/buildAbstract", Bool, true);
SETTING_RW(prefs.queryReplaceAbstract,

View File

@ -58,6 +58,7 @@ class PrefsPack {
bool useDesktopOpen;
// Remember sort state between invocations ?
bool keepSort;
QString sortField;
bool sortActive;
bool sortDesc;
// Abstract preferences. Building abstracts can slow result display

View File

@ -260,8 +260,8 @@ void RclMain::init()
connect(this, SIGNAL(sortDataChanged(DocSeqSortSpec)),
restable, SLOT(onSortDataChanged(DocSeqSortSpec)));
connect(restable->getModel(), SIGNAL(sortColumnChanged(DocSeqSortSpec)),
this, SLOT(onResTableSortBy(DocSeqSortSpec)));
connect(restable->getModel(), SIGNAL(sortDataChanged(DocSeqSortSpec)),
this, SLOT(onSortDataChanged(DocSeqSortSpec)));
connect(restable, SIGNAL(docEditClicked(Rcl::Doc)),
this, SLOT(startNativeViewer(Rcl::Doc)));
connect(restable, SIGNAL(docPreviewClicked(int, Rcl::Doc, int)),
@ -320,11 +320,10 @@ void RclMain::init()
this, SLOT(showQueryDetails()));
if (prefs.keepSort && prefs.sortActive) {
if (prefs.sortDesc)
actionSortByDateDesc->setChecked(true);
else
actionSortByDateAsc->setChecked(true);
onSortCtlChanged();
m_sortspec.field = (const char *)prefs.sortField.toUtf8();
m_sortspec.desc = prefs.sortDesc;
onSortDataChanged(m_sortspec);
emit sortDataChanged(m_sortspec);
}
// Start timer on a slow period (used for checking ^C). Will be
@ -915,23 +914,26 @@ void RclMain::onSortCtlChanged()
m_sortspec.desc = false;
prefs.sortActive = true;
prefs.sortDesc = false;
prefs.sortField = "mtime";
} else if (actionSortByDateDesc->isChecked()) {
m_sortspec.field = "mtime";
m_sortspec.desc = true;
prefs.sortActive = true;
prefs.sortDesc = true;
prefs.sortField = "mtime";
} else {
prefs.sortActive = prefs.sortDesc = false;
prefs.sortField = "";
}
LOGDEB(("RclMain::onCtlDataChanged(): emitting change signals\n"));
if (m_source.isNotNull())
m_source->setSortSpec(m_sortspec);
emit sortDataChanged(m_sortspec);
emit applyFiltSortData();
}
void RclMain::onResTableSortBy(DocSeqSortSpec spec)
void RclMain::onSortDataChanged(DocSeqSortSpec spec)
{
LOGDEB(("RclMain::onSortDataChanged\n"));
m_sortspecnochange = true;
if (spec.field.compare("mtime")) {
actionSortByDateDesc->setChecked(false);
@ -944,6 +946,11 @@ void RclMain::onResTableSortBy(DocSeqSortSpec spec)
if (m_source.isNotNull())
m_source->setSortSpec(spec);
m_sortspec = spec;
prefs.sortField = QString::fromUtf8(spec.field.c_str());
prefs.sortDesc = spec.desc;
prefs.sortActive = !spec.field.empty();
emit applyFiltSortData();
}

View File

@ -97,7 +97,7 @@ public slots:
virtual void on_actionSortByDateAsc_toggled(bool on);
virtual void on_actionSortByDateDesc_toggled(bool on);
virtual void on_actionShowResultsAsTable_toggled(bool on);
virtual void onResTableSortBy(DocSeqSortSpec);
virtual void onSortDataChanged(DocSeqSortSpec);
virtual void resultCount(int);
virtual void showQueryDetails();
virtual void onResultsChanged();

View File

@ -368,7 +368,7 @@ void RecollModel::sort(int column, Qt::SortOrder order)
spec.field = "mtime";
spec.desc = order == Qt::AscendingOrder ? false : true;
}
emit sortColumnChanged(spec);
emit sortDataChanged(spec);
}
///////////////////////////

View File

@ -65,7 +65,7 @@ public:
friend class ResTable;
signals:
void sortColumnChanged(DocSeqSortSpec);
void sortDataChanged(DocSeqSortSpec);
private:
mutable RefCntr<DocSequence> m_source;