cleanup some warnings suppression

This commit is contained in:
Blue 2023-08-15 12:28:25 -03:00
parent 5fbb03fc46
commit 23ec80ccba
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
26 changed files with 630 additions and 924 deletions

View file

@ -29,6 +29,8 @@
#include "messagedelegate.h"
#include "messagefeed.h"
#include "shared/defines.h"
constexpr int textMargin = 2;
constexpr int statusIconSize = 16;
@ -70,27 +72,21 @@ MessageDelegate::MessageDelegate(QObject* parent):
barHeight = bar.sizeHint().height();
}
MessageDelegate::~MessageDelegate()
{
for (const std::pair<const QString, FeedButton*>& pair: *buttons){
MessageDelegate::~MessageDelegate() {
for (const std::pair<const QString, FeedButton*>& pair: *buttons)
delete pair.second;
}
for (const std::pair<const QString, QProgressBar*>& pair: *bars){
for (const std::pair<const QString, QProgressBar*>& pair: *bars)
delete pair.second;
}
for (const std::pair<const QString, QLabel*>& pair: *statusIcons){
for (const std::pair<const QString, QLabel*>& pair: *statusIcons)
delete pair.second;
}
for (const std::pair<const QString, QLabel*>& pair: *pencilIcons){
for (const std::pair<const QString, QLabel*>& pair: *pencilIcons)
delete pair.second;
}
for (const std::pair<const QString, Preview*>& pair: *previews){
for (const std::pair<const QString, Preview*>& pair: *previews)
delete pair.second;
}
delete statusIcons;
delete pencilIcons;
@ -101,29 +97,26 @@ MessageDelegate::~MessageDelegate()
delete bodyRenderer;
}
void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
QVariant vi = index.data(Models::MessageFeed::Bulk);
if (!vi.isValid()) {
if (!vi.isValid())
return;
}
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
painter->save();
painter->setRenderHint(QPainter::Antialiasing, true);
paintBubble(data, painter, option);
bool ntds = needToDrawSender(index, data);
if (ntds || option.rect.y() < 1) {
if (ntds || option.rect.y() < 1)
paintAvatar(data, index, option, painter);
}
QStyleOptionViewItem opt = option;
opt.rect = option.rect.adjusted(bubbleMargin, bubbleMargin, -bubbleMargin, -bubbleMargin / 2);
if (!data.sentByMe) {
if (!data.sentByMe)
opt.displayAlignment = Qt::AlignLeft | Qt::AlignTop;
} else {
else
opt.displayAlignment = Qt::AlignRight | Qt::AlignTop;
}
QRect rect;
if (ntds) {
@ -189,11 +182,11 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
QLabel* pencilIcon = getPencilIcon(data);
pencilIcon->setParent(vp);
if (data.sentByMe) {
if (data.sentByMe)
pencilIcon->move(opt.rect.left() + statusIconSize + margin, currentY);
} else {
else
pencilIcon->move(opt.rect.right() - statusIconSize - margin, currentY);
}
pencilIcon->show();
} else {
std::map<QString, QLabel*>::const_iterator itr = pencilIcons->find(data.id);
@ -205,27 +198,24 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
painter->restore();
if (clearingWidgets) {
if (clearingWidgets)
idsToKeep->insert(data.id);
}
}
void MessageDelegate::paintBubble(const Models::FeedItem& data, QPainter* painter, const QStyleOptionViewItem& option) const
{
void MessageDelegate::paintBubble(const Models::FeedItem& data, QPainter* painter, const QStyleOptionViewItem& option) const {
painter->save();
if (data.sentByMe) {
if (data.sentByMe)
painter->setBrush(option.palette.brush(QPalette::Inactive, QPalette::Highlight));
} else {
else
painter->setBrush(option.palette.brush(QPalette::Window));
}
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(option.rect, bubbleBorderRadius, bubbleBorderRadius);
painter->restore();
}
void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelIndex& index, const QStyleOptionViewItem& option, QPainter* painter) const
{
void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelIndex& index, const QStyleOptionViewItem& option, QPainter* painter) const {
int currentRow = index.row();
int y = option.rect.y();
bool firstAttempt = true;
@ -255,11 +245,10 @@ void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelInde
QPainterPath path;
int ax;
if (data.sentByMe) {
if (data.sentByMe)
ax = option.rect.x() + option.rect.width() + margin;
} else {
else
ax = margin;
}
path.addEllipse(ax, y + margin / 2, avatarHeight, avatarHeight);
painter->save();
@ -268,8 +257,7 @@ void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelInde
painter->restore();
}
bool MessageDelegate::needToDrawAvatar(const QModelIndex& index, const Models::FeedItem& data, const QStyleOptionViewItem& option) const
{
bool MessageDelegate::needToDrawAvatar(const QModelIndex& index, const Models::FeedItem& data, const QStyleOptionViewItem& option) const {
return (option.rect.y() < 1) || needToDrawSender(index, data);
}
@ -285,8 +273,7 @@ bool MessageDelegate::needToDrawSender(const QModelIndex& index, const Models::F
}
}
QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const {
QRect messageRect = option.rect.adjusted(bubbleMargin, margin / 2 + bubbleMargin, -(avatarHeight + 3 * margin + bubbleMargin), -(margin + bubbleMargin) / 2);
QStyleOptionViewItem opt = option;
opt.rect = messageRect;
@ -360,12 +347,10 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
return messageSize;
}
QRect MessageDelegate::getHoveredMessageBodyRect(const QModelIndex& index, const Models::FeedItem& data, const QRect& sizeHint) const
{
QRect MessageDelegate::getHoveredMessageBodyRect(const QModelIndex& index, const Models::FeedItem& data, const QRect& sizeHint) const {
QRect localHint = sizeHint.adjusted(bubbleMargin, bubbleMargin + margin, -bubbleMargin, -bubbleMargin / 2);
if (needToDrawSender(index, data)) {
if (needToDrawSender(index, data))
localHint.adjust(0, nickMetrics.lineSpacing() + textMargin, 0, 0);
}
int attachHeight = 0;
switch (data.attach.state) {
@ -405,8 +390,7 @@ QRect MessageDelegate::getHoveredMessageBodyRect(const QModelIndex& index, const
return localHint;
}
QString MessageDelegate::getAnchor(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
{
QString MessageDelegate::getAnchor(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const {
QVariant vi = index.data(Models::MessageFeed::Bulk);
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
if (data.text.size() > 0) {
@ -425,16 +409,13 @@ QString MessageDelegate::getAnchor(const QPoint& point, const QModelIndex& index
return QString();
}
void MessageDelegate::leftClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
{
void MessageDelegate::leftClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const {
QString anchor = getAnchor(point, index, sizeHint);
if (anchor.size() > 0) {
if (anchor.size() > 0)
emit openLink(anchor);
}
}
QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint)
{
QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) {
QVariant vi = index.data(Models::MessageFeed::Bulk);
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
if (data.text.size() > 0) {
@ -466,8 +447,7 @@ QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex&
return "";
}
Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
{
Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const {
QVariant vi = index.data(Models::MessageFeed::Bulk);
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
if (data.text.size() > 0) {
@ -486,17 +466,15 @@ Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex&
return Shared::Hover::anchor;
} else {
int position = lay->hitTest(translated, Qt::HitTestAccuracy::ExactHit);
if (position != -1) {
if (position != -1)
return Shared::Hover::text;
}
}
}
}
return Shared::Hover::nothing;
}
QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const QModelIndex& index, const QRect& sizeHint)
{
QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const QModelIndex& index, const QRect& sizeHint) {
QVariant vi = index.data(Models::MessageFeed::Bulk);
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
if (data.text.size() > 0) {
@ -529,30 +507,24 @@ QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const
return "";
}
QString MessageDelegate::clearSelection()
{
QString MessageDelegate::clearSelection() {
QString lastSelectedId = currentId;
currentId = "";
selection = std::pair(0, 0);
return lastSelectedId;
}
bool MessageDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
{
bool MessageDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) {
//qDebug() << event->type();
return QStyledItemDelegate::editorEvent(event, model, option, index);
}
int MessageDelegate::paintButton(QPushButton* btn, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const
{
int MessageDelegate::paintButton(QPushButton* btn, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const {
QPoint start;
if (sentByMe) {
if (sentByMe)
start = {option.rect.x() + option.rect.width() - btn->width(), option.rect.top()};
} else {
else
start = option.rect.topLeft();
}
QWidget* vp = static_cast<QWidget*>(painter->device());
btn->setParent(vp);
@ -563,8 +535,7 @@ int MessageDelegate::paintButton(QPushButton* btn, QPainter* painter, bool sentB
return btn->width();
}
int MessageDelegate::paintComment(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const
{
int MessageDelegate::paintComment(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const {
painter->setFont(dateFont);
QColor q = painter->pen().color();
q.setAlpha(180);
@ -576,8 +547,8 @@ int MessageDelegate::paintComment(const Models::FeedItem& data, QPainter* painte
return rect.width();
}
int MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const
{
int MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const {
SHARED_UNUSED(sentByMe);
QPoint start = option.rect.topLeft();
bar->resize(option.rect.width(), barHeight);
@ -589,8 +560,7 @@ int MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByM
return option.rect.width();
}
int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const
{
int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const {
Preview* preview = 0;
std::map<QString, Preview*>::iterator itr = previews->find(data.id);
@ -605,18 +575,16 @@ int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painte
previews->insert(std::make_pair(data.id, preview));
}
if (!preview->isFileReachable()) { //this is the situation when the file preview couldn't be painted because the file was moved
if (!preview->isFileReachable()) //this is the situation when the file preview couldn't be painted because the file was moved
emit invalidPath(data.id); //or deleted. This signal notifies the model, and the model notifies the core, preview can
} //handle being invalid for as long as I need and can be even become valid again with a new path
//handle being invalid for as long as I need and can be even become valid again with a new path
QSize pSize(preview->size());
option.rect.adjust(0, pSize.height() + textMargin, 0, 0);
return pSize.width();
}
QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
{
QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const {
std::map<QString, FeedButton*>::const_iterator itr = buttons->find(data.id);
FeedButton* result = 0;
if (itr != buttons->end()) {
@ -640,8 +608,7 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
return result;
}
QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const
{
QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const {
std::map<QString, QProgressBar*>::const_iterator barItr = bars->find(data.id);
QProgressBar* result = 0;
if (barItr != bars->end()) {
@ -665,8 +632,7 @@ QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const
return result;
}
QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const
{
QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const {
std::map<QString, QLabel*>::const_iterator itr = statusIcons->find(data.id);
QLabel* result = 0;
@ -680,9 +646,8 @@ QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const
QIcon q(Shared::icon(Shared::messageStateThemeIcons[static_cast<uint8_t>(data.state)]));
QString tt = Shared::Global::getName(data.state);
if (data.state == Shared::Message::State::error) {
if (data.error > 0) {
if (data.error > 0)
tt += ": " + data.error;
}
}
if (result->toolTip() != tt) { //If i just assign pixmap every time unconditionally
result->setPixmap(q.pixmap(statusIconSize)); //it invokes an infinite cycle of repaint
@ -692,8 +657,7 @@ QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const
return result;
}
QLabel * MessageDelegate::getPencilIcon(const Models::FeedItem& data) const
{
QLabel * MessageDelegate::getPencilIcon(const Models::FeedItem& data) const {
std::map<QString, QLabel*>::const_iterator itr = pencilIcons->find(data.id);
QLabel* result = 0;
@ -755,14 +719,12 @@ int MessageDelegate::paintBody(const Models::FeedItem& data, QPainter* painter,
return 0;
}
void MessageDelegate::beginClearWidgets()
{
void MessageDelegate::beginClearWidgets() {
idsToKeep->clear();
clearingWidgets = true;
}
void MessageDelegate::endClearWidgets()
{
void MessageDelegate::endClearWidgets() {
if (clearingWidgets) {
removeElements(buttons, idsToKeep);
removeElements(bars, idsToKeep);
@ -775,14 +737,12 @@ void MessageDelegate::endClearWidgets()
}
}
void MessageDelegate::onButtonPushed() const
{
void MessageDelegate::onButtonPushed() const {
FeedButton* btn = static_cast<FeedButton*>(sender());
emit buttonPushed(btn->messageId);
}
void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const
{
void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const {
std::map<QString, FeedButton*>::const_iterator itr = buttons->find(data.id);
if (itr != buttons->end()) {
delete itr->second;