Fixed shrinked toolbar when messages text is to short.

This commit is contained in:
Martin Rotter 2020-12-11 07:41:11 +01:00
parent c8b1b900df
commit 46133e5204
4 changed files with 41 additions and 6 deletions

View file

@ -159,12 +159,11 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
switch (decision) { switch (decision) {
case MessageObject::FilteringAction::Accept: case MessageObject::FilteringAction::Accept:
// Message is normally accepted, it could be tweaked by the filter. // Message is normally accepted, it could be tweaked by the filter.
continue; continue;
case MessageObject::FilteringAction::Ignore: case MessageObject::FilteringAction::Ignore:
default:
// Remove the message, we do not want it. // Remove the message, we do not want it.
remove_msg = true; remove_msg = true;
break; break;
@ -201,7 +200,8 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
// Label is not there anymore, it was deassigned. // Label is not there anymore, it was deassigned.
lbl->deassignFromMessage(*msg_orig); lbl->deassignFromMessage(*msg_orig);
qDebugNN << "It was detected that label" << QUOTE_W_SPACE(lbl->customId()) qDebugNN << LOGSEC_FEEDDOWNLOADER
<< "It was detected that label" << QUOTE_W_SPACE(lbl->customId())
<< "was DEASSIGNED from message" << QUOTE_W_SPACE(msg_orig->m_customId) << "was DEASSIGNED from message" << QUOTE_W_SPACE(msg_orig->m_customId)
<< "by message filter(s)."; << "by message filter(s).";
} }
@ -213,7 +213,8 @@ void FeedDownloader::updateOneFeed(Feed* feed) {
// was newly assigned. // was newly assigned.
lbl->assignToMessage(*msg_orig); lbl->assignToMessage(*msg_orig);
qDebugNN << "It was detected that label" << QUOTE_W_SPACE(lbl->customId()) qDebugNN << LOGSEC_FEEDDOWNLOADER
<< "It was detected that label" << QUOTE_W_SPACE(lbl->customId())
<< "was ASSIGNED to message" << QUOTE_W_SPACE(msg_orig->m_customId) << "was ASSIGNED to message" << QUOTE_W_SPACE(msg_orig->m_customId)
<< "by message filter(s)."; << "by message filter(s).";
} }

View file

@ -58,10 +58,12 @@ MessagePreviewer::MessagePreviewer(bool should_resize_to_fit, QWidget* parent)
m_txtMessage = new MessageBrowser(should_resize_to_fit, this); m_txtMessage = new MessageBrowser(should_resize_to_fit, this);
#endif #endif
m_toolBar->setOrientation(Qt::Orientation::Vertical);
// NOTE: To make sure that if we have many labels and short message // NOTE: To make sure that if we have many labels and short message
// that whole toolbar is visible.
m_toolBar->setSizePolicy(m_toolBar->sizePolicy().horizontalPolicy(), QSizePolicy::Policy::MinimumExpanding); m_toolBar->setSizePolicy(m_toolBar->sizePolicy().horizontalPolicy(), QSizePolicy::Policy::MinimumExpanding);
m_toolBar->setOrientation(Qt::Orientation::Vertical);
m_layout->setContentsMargins(3, 3, 3, 3); m_layout->setContentsMargins(3, 3, 3, 3);
m_layout->addWidget(m_txtMessage, 0, 1, 1, 1); m_layout->addWidget(m_txtMessage, 0, 1, 1, 1);
m_layout->addWidget(m_toolBar, 0, 0, -1, 1); m_layout->addWidget(m_toolBar, 0, 0, -1, 1);
@ -210,7 +212,7 @@ void MessagePreviewer::updateLabels(bool only_clear) {
return; return;
} }
if (m_root.data() != nullptr && m_root.data()->getParentServiceRoot()->labelsNode()->labels().size() > 0) { if (m_root.data() != nullptr && !m_root.data()->getParentServiceRoot()->labelsNode()->labels().isEmpty()) {
m_separator = m_toolBar->addSeparator(); m_separator = m_toolBar->addSeparator();
QSqlDatabase database = qApp->database()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->connection(metaObject()->className());

View file

@ -2,6 +2,7 @@
#include "miscellaneous/databasequeries.h" #include "miscellaneous/databasequeries.h"
#include "3rd-party/boolinq/boolinq.h"
#include "exceptions/applicationexception.h" #include "exceptions/applicationexception.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
@ -132,6 +133,36 @@ QList<Label*> DatabaseQueries::getLabels(const QSqlDatabase& db, int account_id)
return labels; return labels;
} }
QList<Label*> DatabaseQueries::getLabelsForMessage(const QSqlDatabase& db,
const Message& msg,
const QList<Label*> installed_labels) {
QList<Label*> labels;
QSqlQuery q(db);
q.setForwardOnly(true);
q.prepare("SELECT DISTINCT label FROM LabelsInMessages WHERE message = :message AND account_id = :account_id;");
q.bindValue(QSL(":account_id"), msg.m_accountId);
q.bindValue(QSL(":message"), msg.m_customId);
if (q.exec()) {
auto iter = boolinq::from(installed_labels);
while (q.next()) {
auto lbl_id = q.value(0).toString();
Label* candidate_label = iter.firstOrDefault([&](const Label* lbl) {
return lbl->customId() == lbl_id;
});
if (candidate_label != nullptr) {
labels << candidate_label;
}
}
}
return labels;
}
bool DatabaseQueries::updateLabel(const QSqlDatabase& db, Label* label) { bool DatabaseQueries::updateLabel(const QSqlDatabase& db, Label* label) {
QSqlQuery q(db); QSqlQuery q(db);

View file

@ -24,6 +24,7 @@ class DatabaseQueries {
static bool assignLabelToMessage(const QSqlDatabase& db, Label* label, const Message& msg); static bool assignLabelToMessage(const QSqlDatabase& db, Label* label, const Message& msg);
static bool setLabelsForMessage(const QSqlDatabase& db, const QList<Label*>& labels, const Message& msg); static bool setLabelsForMessage(const QSqlDatabase& db, const QList<Label*>& labels, const Message& msg);
static QList<Label*> getLabels(const QSqlDatabase& db, int account_id); static QList<Label*> getLabels(const QSqlDatabase& db, int account_id);
static QList<Label*> getLabelsForMessage(const QSqlDatabase& db, const Message& msg, const QList<Label*> installed_labels);
static bool updateLabel(const QSqlDatabase& db, Label* label); static bool updateLabel(const QSqlDatabase& db, Label* label);
static bool deleteLabel(const QSqlDatabase& db, Label* label); static bool deleteLabel(const QSqlDatabase& db, Label* label);
static bool createLabel(const QSqlDatabase& db, Label* label, int account_id); static bool createLabel(const QSqlDatabase& db, Label* label, int account_id);