Fix sort state not correctly activated when set from saved state

This commit is contained in:
Jean-Francois Dockes 2020-11-25 10:28:15 +01:00
parent 8fd9d02900
commit 01aa85fd1c
7 changed files with 22 additions and 38 deletions

View File

@ -403,7 +403,6 @@ int main(int argc, char **argv)
QTimer::singleShot(0, mainWindow, SLOT(initDbOpen()));
mainWindow->sSearch->searchTypCMB->setCurrentIndex(prefs.ssearchTyp);
mainWindow->sSearch->searchTypeChanged(prefs.ssearchTyp);
if (op_flags & OPT_q) {
SSearch::SSearchType stype;
if (op_flags & OPT_o) {

View File

@ -70,8 +70,6 @@
#include "readfile.h"
#include "moc_rclmain_w.cpp"
using std::pair;
QString g_stringAllStem, g_stringNoStem;
static const char *settingskey_toolarea="/Recoll/geometry/toolArea";
static const char *settingskey_resarea="/Recoll/geometry/resArea";
@ -125,9 +123,6 @@ void RclMain::init()
{
setWindowTitle(configToTitle());
DocSequence::set_translations(
qs2utf8s(tr("sorted")), qs2utf8s(tr("filtered")));
buildMenus();
// A shortcut to get the focus back to the search entry, in table
@ -183,8 +178,6 @@ void RclMain::init()
connect(sSearch,
SIGNAL(startSearch(std::shared_ptr<Rcl::SearchData>, bool)),
this, SLOT(startSearch(std::shared_ptr<Rcl::SearchData>, bool)));
connect(sSearch, SIGNAL(searchTypeChanged(int)),
this, SLOT(onSearchTypeChanged(int)));
connect(sSearch, SIGNAL(setDescription(QString)),
this, SLOT(onSetDescription(QString)));
connect(sSearch, SIGNAL(clearSearch()),
@ -268,6 +261,8 @@ void RclMain::init()
restable, SLOT(readDocSource()));
connect(this, SIGNAL(sortDataChanged(DocSeqSortSpec)),
restable, SLOT(onSortDataChanged(DocSeqSortSpec)));
connect(this, SIGNAL(sortDataChanged(DocSeqSortSpec)),
this, SLOT(onSortDataChanged(DocSeqSortSpec)));
connect(this, SIGNAL(uiPrefsChanged()), restable, SLOT(onUiPrefsChanged()));
connect(restable->getModel(), SIGNAL(sortDataChanged(DocSeqSortSpec)),
@ -330,7 +325,6 @@ void RclMain::init()
if (prefs.keepSort && prefs.sortActive) {
m_sortspec.field = (const char *)prefs.sortField.toUtf8();
m_sortspec.desc = prefs.sortDesc;
onSortDataChanged(m_sortspec);
emit sortDataChanged(m_sortspec);
}
QSettings settings;
@ -775,21 +769,6 @@ void RclMain::fileExit()
qApp->exit(0);
}
// Reset sort order when search type changes.
void RclMain::onSearchTypeChanged(int stp)
{
SSearch::SSearchType tp = (SSearch::SSearchType)stp;
switch (tp) {
case SSearch::SST_FNM:
m_sortspec.desc = false;
m_sortspec.field = "mtype";
break;
default:
m_sortspec.reset();
break;
};
}
// Start a db query and set the reslist docsource
void RclMain::startSearch(std::shared_ptr<Rcl::SearchData> sdata, bool issimple)
{
@ -831,7 +810,7 @@ void RclMain::startSearch(std::shared_ptr<Rcl::SearchData> sdata, bool issimple)
curPreview = 0;
DocSequenceDb *src =
new DocSequenceDb(rcldb, std::shared_ptr<Rcl::Query>(query),
string(tr("Query results").toUtf8()), sdata);
qs2utf8s(tr("Query results")), sdata);
src->setAbstractParams(prefs.queryBuildAbstract,
prefs.queryReplaceAbstract);
m_source = std::shared_ptr<DocSequence>(src);
@ -981,6 +960,14 @@ void RclMain::onSortDataChanged(DocSeqSortSpec spec)
prefs.sortDesc = spec.desc;
prefs.sortActive = !spec.field.empty();
std::string fld;
if (!m_sortspec.field.empty()) {
fld = qs2utf8s(RecollModel::displayableField(m_sortspec.field));
}
DocSequence::set_translations(
qs2utf8s(tr("sorted")) + ": " + fld +
(m_sortspec.desc?" &darr;":" &uarr;"),
qs2utf8s(tr("filtered")));
initiateQuery();
}

View File

@ -146,7 +146,6 @@ public slots:
virtual void previewPrevInTab(Preview *, int sid, int docnum);
virtual void previewExposed(Preview *, int sid, int docnum);
virtual void resetSearch();
virtual void onSearchTypeChanged(int);
virtual void eraseDocHistory();
virtual void eraseSearchHistory();
virtual void exportSimpleSearchHistory();

View File

@ -255,7 +255,7 @@ RecollModel::RecollModel(const QStringList fields, ResTable *tb,
o_displayableFields["relevancyrating"] = tr("Relevancy rating");
o_displayableFields["title"] = tr("Title");
o_displayableFields["url"] = tr("URL");
o_displayableFields["mtime"] = tr("Mtime");
o_displayableFields["mtime"] = tr("Date");
o_displayableFields["date"] = tr("Date");
o_displayableFields["datetime"] = tr("Date and time");
@ -346,6 +346,12 @@ void RecollModel::addColumn(int col, const string& field)
}
}
QString RecollModel::displayableField(const std::string& in)
{
const auto it = o_displayableFields.find(in);
return (it == o_displayableFields.end()) ? u8s2qs(in) : it->second;
}
QVariant RecollModel::headerData(int idx, Qt::Orientation orientation,
int role) const
{
@ -357,12 +363,7 @@ QVariant RecollModel::headerData(int idx, Qt::Orientation orientation,
}
if (orientation == Qt::Horizontal && role == Qt::DisplayRole &&
idx < int(m_fields.size())) {
map<string, QString>::const_iterator it =
o_displayableFields.find(m_fields[idx]);
if (it == o_displayableFields.end())
return QString::fromUtf8(m_fields[idx].c_str());
else
return it->second;
return displayableField(m_fields[idx]);
}
return QVariant();
}

View File

@ -56,10 +56,10 @@ public:
virtual std::shared_ptr<DocSequence> getDocSource() {return m_source;}
virtual void deleteColumn(int);
virtual const std::vector<std::string>& getFields() {return m_fields;}
virtual const std::map<std::string, QString>& getAllFields()
{
return o_displayableFields;
static const std::map<std::string, QString>& getAllFields() {
return o_displayableFields;
}
static QString displayableField(const std::string& in);
virtual void addColumn(int, const std::string&);
// Some column name are aliases/translator for base document field
// (ie: date, datetime->mtime). Help deal with this:

View File

@ -441,7 +441,6 @@ void SSearch::onSearchTypeChanged(int typ)
default:
queryText->setToolTip(tr("Enter search terms here."));
}
emit searchTypeChanged((int)typ);
}
void SSearch::startSimpleSearch()

View File

@ -106,7 +106,6 @@ private slots:
virtual void onCompleterShown();
signals:
void searchTypeChanged(int);
void startSearch(std::shared_ptr<Rcl::SearchData>, bool);
void setDescription(QString);
void clearSearch();