fix #1415
This commit is contained in:
parent
24f74394e1
commit
66d70f2b7f
8 changed files with 51 additions and 15 deletions
|
@ -142,21 +142,24 @@ MessagesModelCache* MessagesModel::cache() const {
|
||||||
return m_cache;
|
return m_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesModel::repopulate() {
|
void MessagesModel::repopulate(int additional_article_id) {
|
||||||
m_cache->clear();
|
m_cache->clear();
|
||||||
setQuery(selectStatement(), m_db);
|
|
||||||
|
QString statemnt = selectStatement(additional_article_id);
|
||||||
|
|
||||||
|
setQuery(statemnt, m_db);
|
||||||
|
|
||||||
if (lastError().isValid()) {
|
if (lastError().isValid()) {
|
||||||
qCriticalNN << LOGSEC_MESSAGEMODEL << "Error when setting new msg view query: '" << lastError().text() << "'.";
|
qCriticalNN << LOGSEC_MESSAGEMODEL
|
||||||
qCriticalNN << LOGSEC_MESSAGEMODEL << "Used SQL select statement: '" << selectStatement() << "'.";
|
<< "Error when setting new msg view query:" << QUOTE_W_SPACE_DOT(lastError().text());
|
||||||
|
qCriticalNN << LOGSEC_MESSAGEMODEL << "Used SQL select statement:" << QUOTE_W_SPACE_DOT(statemnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (canFetchMore()) {
|
while (canFetchMore()) {
|
||||||
fetchMore();
|
fetchMore();
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebugNN << LOGSEC_MESSAGEMODEL << "Repopulated model, SQL statement is now:\n"
|
qDebugNN << LOGSEC_MESSAGEMODEL << "Repopulated model, SQL statement is now:\n" << QUOTE_W_SPACE_DOT(statemnt);
|
||||||
<< QUOTE_W_SPACE_DOT(selectStatement());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MessagesModel::setData(const QModelIndex& idx, const QVariant& value, int role) {
|
bool MessagesModel::setData(const QModelIndex& idx, const QVariant& value, int role) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer {
|
||||||
|
|
||||||
// Fetches ALL available data to the model.
|
// Fetches ALL available data to the model.
|
||||||
// NOTE: This activates the SQL query and populates the model with new data.
|
// NOTE: This activates the SQL query and populates the model with new data.
|
||||||
void repopulate();
|
void repopulate(int additional_article_id = 0);
|
||||||
|
|
||||||
// Model implementation.
|
// Model implementation.
|
||||||
bool setData(const QModelIndex& idx, const QVariant& value, int role = Qt::EditRole);
|
bool setData(const QModelIndex& idx, const QVariant& value, int role = Qt::EditRole);
|
||||||
|
|
|
@ -96,12 +96,21 @@ bool MessagesModelSqlLayer::isColumnNumeric(int column_id) const {
|
||||||
return m_numericColumns.contains(column_id);
|
return m_numericColumns.contains(column_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessagesModelSqlLayer::selectStatement() const {
|
QString MessagesModelSqlLayer::selectStatement(int additional_article_id) const {
|
||||||
|
QString fltr;
|
||||||
|
|
||||||
|
if (additional_article_id <= 0) {
|
||||||
|
fltr = m_filter;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fltr = QSL("(%1) OR Messages.id = %2").arg(m_filter, QString::number(additional_article_id));
|
||||||
|
}
|
||||||
|
|
||||||
return QL1S("SELECT ") + formatFields() + QL1C(' ') +
|
return QL1S("SELECT ") + formatFields() + QL1C(' ') +
|
||||||
QL1S("FROM Messages LEFT JOIN Feeds ON Messages.feed = Feeds.custom_id AND Messages.account_id = "
|
QL1S("FROM Messages LEFT JOIN Feeds ON Messages.feed = Feeds.custom_id AND Messages.account_id = "
|
||||||
"Feeds.account_id "
|
"Feeds.account_id "
|
||||||
"WHERE ") +
|
"WHERE ") +
|
||||||
m_filter + orderByClause() + QL1C(';');
|
fltr + orderByClause() + QL1C(';');
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessagesModelSqlLayer::orderByClause() const {
|
QString MessagesModelSqlLayer::orderByClause() const {
|
||||||
|
|
|
@ -27,7 +27,7 @@ class MessagesModelSqlLayer {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString orderByClause() const;
|
QString orderByClause() const;
|
||||||
QString selectStatement() const;
|
QString selectStatement(int additional_article_id = -1) const;
|
||||||
QString formatFields() const;
|
QString formatFields() const;
|
||||||
|
|
||||||
bool isColumnNumeric(int column_id) const;
|
bool isColumnNumeric(int column_id) const;
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
MessagesProxyModel::MessagesProxyModel(MessagesModel* source_model, QObject* parent)
|
MessagesProxyModel::MessagesProxyModel(MessagesModel* source_model, QObject* parent)
|
||||||
: QSortFilterProxyModel(parent), m_sourceModel(source_model), m_filter(MessageListFilter::NoFiltering) {
|
: QSortFilterProxyModel(parent), m_sourceModel(source_model), m_filter(MessageListFilter::NoFiltering),
|
||||||
|
m_additionalArticleId(0) {
|
||||||
setObjectName(QSL("MessagesProxyModel"));
|
setObjectName(QSL("MessagesProxyModel"));
|
||||||
|
|
||||||
initializeFilters();
|
initializeFilters();
|
||||||
|
@ -118,6 +119,11 @@ bool MessagesProxyModel::filterAcceptsMessage(int msg_row_index) const {
|
||||||
if (m_filter == MessageListFilter::NoFiltering) {
|
if (m_filter == MessageListFilter::NoFiltering) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (m_additionalArticleId > 0 &&
|
||||||
|
m_sourceModel->data(msg_row_index, MSG_DB_ID_INDEX, Qt::ItemDataRole::EditRole).toInt() ==
|
||||||
|
m_additionalArticleId) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (MessageListFilter val : m_filterKeys) {
|
for (MessageListFilter val : m_filterKeys) {
|
||||||
if (Globals::hasFlag(m_filter, val) && m_filters[val](msg_row_index)) {
|
if (Globals::hasFlag(m_filter, val) && m_filters[val](msg_row_index)) {
|
||||||
|
@ -225,8 +231,17 @@ bool MessagesProxyModel::filterAcceptsRow(int source_row, const QModelIndex& sou
|
||||||
(m_sourceModel->cache()->containsData(source_row) || filterAcceptsMessage(source_row));
|
(m_sourceModel->cache()->containsData(source_row) || filterAcceptsMessage(source_row));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MessagesProxyModel::additionalArticleId() const {
|
||||||
|
return m_additionalArticleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessagesProxyModel::setAdditionalArticleId(int newAdditionalArticleId) {
|
||||||
|
m_additionalArticleId = newAdditionalArticleId;
|
||||||
|
}
|
||||||
|
|
||||||
void MessagesProxyModel::setMessageListFilter(MessageListFilter filter) {
|
void MessagesProxyModel::setMessageListFilter(MessageListFilter filter) {
|
||||||
m_filter = filter;
|
m_filter = filter;
|
||||||
|
m_additionalArticleId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QModelIndexList MessagesProxyModel::mapListFromSource(const QModelIndexList& indexes, bool deep) const {
|
QModelIndexList MessagesProxyModel::mapListFromSource(const QModelIndexList& indexes, bool deep) const {
|
||||||
|
|
|
@ -52,6 +52,9 @@ class MessagesProxyModel : public QSortFilterProxyModel {
|
||||||
// Performs sort of items.
|
// Performs sort of items.
|
||||||
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
|
|
||||||
|
int additionalArticleId() const;
|
||||||
|
void setAdditionalArticleId(int newAdditionalArticleId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initializeFilters();
|
void initializeFilters();
|
||||||
|
|
||||||
|
@ -68,6 +71,7 @@ class MessagesProxyModel : public QSortFilterProxyModel {
|
||||||
MessageListFilter m_filter;
|
MessageListFilter m_filter;
|
||||||
QMap<MessageListFilter, std::function<bool(int)>> m_filters;
|
QMap<MessageListFilter, std::function<bool(int)>> m_filters;
|
||||||
QList<MessageListFilter> m_filterKeys;
|
QList<MessageListFilter> m_filterKeys;
|
||||||
|
int m_additionalArticleId;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(MessagesProxyModel::MessageListFilter)
|
Q_DECLARE_METATYPE(MessagesProxyModel::MessageListFilter)
|
||||||
|
|
|
@ -175,15 +175,17 @@ void MessagesView::sort(int column,
|
||||||
bool repopulate_data,
|
bool repopulate_data,
|
||||||
bool change_header,
|
bool change_header,
|
||||||
bool emit_changed_from_header,
|
bool emit_changed_from_header,
|
||||||
bool ignore_multicolumn_sorting) {
|
bool ignore_multicolumn_sorting,
|
||||||
|
int additional_article_id) {
|
||||||
if (change_header && !emit_changed_from_header) {
|
if (change_header && !emit_changed_from_header) {
|
||||||
header()->blockSignals(true);
|
header()->blockSignals(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sourceModel->addSortState(column, order, ignore_multicolumn_sorting);
|
m_sourceModel->addSortState(column, order, ignore_multicolumn_sorting);
|
||||||
|
m_proxyModel->setAdditionalArticleId(additional_article_id);
|
||||||
|
|
||||||
if (repopulate_data) {
|
if (repopulate_data) {
|
||||||
m_sourceModel->repopulate();
|
m_sourceModel->repopulate(additional_article_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (change_header) {
|
if (change_header) {
|
||||||
|
@ -209,6 +211,8 @@ void MessagesView::keyboardSearch(const QString& search) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesView::reloadSelections() {
|
void MessagesView::reloadSelections() {
|
||||||
|
bool force_load_currently_selected_article = true;
|
||||||
|
|
||||||
const QDateTime dt1 = QDateTime::currentDateTime();
|
const QDateTime dt1 = QDateTime::currentDateTime();
|
||||||
QModelIndex current_index = selectionModel()->currentIndex();
|
QModelIndex current_index = selectionModel()->currentIndex();
|
||||||
const bool is_current_selected =
|
const bool is_current_selected =
|
||||||
|
@ -221,7 +225,7 @@ void MessagesView::reloadSelections() {
|
||||||
bool do_not_mark_read_on_select = false;
|
bool do_not_mark_read_on_select = false;
|
||||||
|
|
||||||
// Reload the model now.
|
// Reload the model now.
|
||||||
sort(col, ord, true, false, false, true);
|
sort(col, ord, true, false, false, true, force_load_currently_selected_article ? selected_message_id : 0);
|
||||||
|
|
||||||
// Now, we must find the same previously focused message.
|
// Now, we must find the same previously focused message.
|
||||||
if (selected_message_id > 0) {
|
if (selected_message_id > 0) {
|
||||||
|
|
|
@ -120,7 +120,8 @@ class MessagesView : public BaseTreeView {
|
||||||
bool repopulate_data,
|
bool repopulate_data,
|
||||||
bool change_header,
|
bool change_header,
|
||||||
bool emit_changed_from_header,
|
bool emit_changed_from_header,
|
||||||
bool ignore_multicolumn_sorting);
|
bool ignore_multicolumn_sorting,
|
||||||
|
int additional_article_id = 0);
|
||||||
|
|
||||||
// Creates needed connections.
|
// Creates needed connections.
|
||||||
void createConnections();
|
void createConnections();
|
||||||
|
|
Loading…
Add table
Reference in a new issue