PVS: V629 Consider inspecting the 'col.red() << 24' expression. Bit shifting of the 32-bit value with a subsequent expansion to the 64-bit type.

This commit is contained in:
wmayer
2019-02-17 22:27:00 +01:00
parent 2bb5797568
commit f0320d954a
5 changed files with 71 additions and 59 deletions

View File

@@ -39,7 +39,7 @@ namespace Gui {
namespace Dialog {
struct DlgSettingsEditorP
{
QVector<QPair<QString, unsigned long> > colormap; // Color map
QVector<QPair<QString, unsigned int> > colormap; // Color map
};
} // namespace Dialog
} // namespace Gui
@@ -60,70 +60,70 @@ DlgSettingsEditorImp::DlgSettingsEditorImp( QWidget* parent )
d = new DlgSettingsEditorP();
QColor col;
col = Qt::black;
unsigned long lText = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lText = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Text")), lText));
col = Qt::cyan;
unsigned long lBookmarks = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lBookmarks = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Bookmark")), lBookmarks));
col = Qt::red;
unsigned long lBreakpnts = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lBreakpnts = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Breakpoint")), lBreakpnts));
col = Qt::blue;
unsigned long lKeywords = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lKeywords = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Keyword")), lKeywords));
col.setRgb(0, 170, 0);
unsigned long lComments = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lComments = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Comment")), lComments));
col.setRgb(160, 160, 164);
unsigned long lBlockCom = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lBlockCom = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Block comment")), lBlockCom));
col = Qt::blue;
unsigned long lNumbers = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lNumbers = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Number")), lNumbers));
col = Qt::red;
unsigned long lStrings = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lStrings = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("String")), lStrings));
col = Qt::red;
unsigned long lCharacter = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lCharacter = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Character")), lCharacter));
col.setRgb(255, 170, 0);
unsigned long lClass = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lClass = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Class name")), lClass));
col.setRgb(255, 170, 0);
unsigned long lDefine = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lDefine = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Define name")), lDefine));
col.setRgb(160, 160, 164);
unsigned long lOperat = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lOperat = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Operator")), lOperat));
col.setRgb(170, 170, 127);
unsigned long lPyOutput = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lPyOutput = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Python output")), lPyOutput));
col = Qt::red;
unsigned long lPyError = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lPyError = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Python error")), lPyError));
col.setRgb(224, 224, 224);
unsigned long lCLine = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned long>
unsigned int lCLine = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Current line highlight")), lCLine));
QStringList labels; labels << tr("Items");
this->displayItems->setHeaderLabels(labels);
this->displayItems->header()->hide();
for (QVector<QPair<QString, unsigned long> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it) {
for (QVector<QPair<QString, unsigned int> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it) {
QTreeWidgetItem* item = new QTreeWidgetItem(this->displayItems);
item->setText(0, tr((*it).first.toLatin1()));
}
@@ -146,7 +146,7 @@ DlgSettingsEditorImp::~DlgSettingsEditorImp()
void DlgSettingsEditorImp::on_displayItems_currentItemChanged(QTreeWidgetItem *item)
{
int index = displayItems->indexOfTopLevelItem(item);
unsigned long col = d->colormap[index].second;
unsigned int col = d->colormap[index].second;
colorButton->setColor(QColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff));
}
@@ -154,7 +154,7 @@ void DlgSettingsEditorImp::on_displayItems_currentItemChanged(QTreeWidgetItem *i
void DlgSettingsEditorImp::on_colorButton_changed()
{
QColor col = colorButton->color();
unsigned long lcol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
unsigned int lcol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
int index = displayItems->indexOfTopLevelItem(displayItems->currentItem());
d->colormap[index].second = lcol;
@@ -172,8 +172,10 @@ void DlgSettingsEditorImp::saveSettings()
// Saves the color map
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Editor");
for (QVector<QPair<QString, unsigned long> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it)
hGrp->SetUnsigned((*it).first.toLatin1(), (*it).second);
for (QVector<QPair<QString, unsigned int> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it) {
unsigned long col = static_cast<unsigned long>((*it).second);
hGrp->SetUnsigned((*it).first.toLatin1(), col);
}
hGrp->SetInt( "FontSize", fontSize->value() );
hGrp->SetASCII( "Font", fontFamily->currentText().toLatin1() );
@@ -202,9 +204,10 @@ void DlgSettingsEditorImp::loadSettings()
// Restores the color map
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Editor");
for (QVector<QPair<QString, unsigned long> >::Iterator it = d->colormap.begin(); it != d->colormap.end(); ++it){
unsigned long col = hGrp->GetUnsigned((*it).first.toLatin1(), (*it).second);
(*it).second = col;
for (QVector<QPair<QString, unsigned int> >::Iterator it = d->colormap.begin(); it != d->colormap.end(); ++it){
unsigned long col = static_cast<unsigned long>((*it).second);
col = hGrp->GetUnsigned((*it).first.toLatin1(), col);
(*it).second = static_cast<unsigned int>(col);
QColor color;
color.setRgb((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff);
pythonSyntax->setColor( (*it).first, color );
@@ -235,7 +238,7 @@ void DlgSettingsEditorImp::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange) {
int index = 0;
for (QVector<QPair<QString, unsigned long> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it)
for (QVector<QPair<QString, unsigned int> >::ConstIterator it = d->colormap.begin(); it != d->colormap.end(); ++it)
this->displayItems->topLevelItem(index++)->setText(0, tr((*it).first.toLatin1()));
this->retranslateUi(this);
} else {

View File

@@ -429,12 +429,14 @@ void PrefColorButton::restorePreferences()
QColor col = color();
unsigned long lcol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8);
unsigned long lcol = static_cast<unsigned long>(icol);
lcol = getWindowParameter()->GetUnsigned( entryName(), lcol );
int r = (lcol >> 24)&0xff;
int g = (lcol >> 16)&0xff;
int b = (lcol >> 8)&0xff;
icol = static_cast<unsigned int>(lcol);
int r = (icol >> 24)&0xff;
int g = (icol >> 16)&0xff;
int b = (icol >> 8)&0xff;
setColor(QColor(r,g,b));
}
@@ -449,9 +451,8 @@ void PrefColorButton::savePreferences()
QColor col = color();
// (r,g,b,a) with a = 255 (opaque)
unsigned long lcol = (static_cast<unsigned long> (col.red()) << 24)
| (static_cast<unsigned long> (col.green()) << 16)
| (static_cast<unsigned long> (col.blue()) << 8) | 255;
unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8) | 255;
unsigned long lcol = static_cast<unsigned long>(icol);
getWindowParameter()->SetUnsigned( entryName(), lcol );
}

View File

@@ -514,8 +514,10 @@ void PythonConsole::OnChange( Base::Subject<const char*> &rCaller,const char* sR
QMap<QString, QColor>::ConstIterator it = d->colormap.find(QString::fromLatin1(sReason));
if (it != d->colormap.end()) {
QColor color = it.value();
unsigned long col = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
col = hPrefGrp->GetUnsigned( sReason, col);
unsigned int col = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
unsigned long value = static_cast<unsigned long>(col);
value = hPrefGrp->GetUnsigned(sReason, value);
col = static_cast<unsigned int>(value);
color.setRgb((col>>24)&0xff, (col>>16)&0xff, (col>>8)&0xff);
pythonSyntax->setColor(QString::fromLatin1(sReason), color);
}
@@ -929,10 +931,11 @@ void PythonConsole::changeEvent(QEvent *e)
else if (e->type() == QEvent::StyleChange) {
QPalette pal = palette();
QColor color = pal.windowText().color();
unsigned long text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
unsigned int text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
unsigned long value = static_cast<unsigned long>(text);
// if this parameter is not already set use the style's window text color
text = getWindowParameter()->GetUnsigned("Text", text);
getWindowParameter()->SetUnsigned("Text", text);
value = getWindowParameter()->GetUnsigned("Text", value);
getWindowParameter()->SetUnsigned("Text", value);
}
TextEdit::changeEvent(e);
}

View File

@@ -378,10 +378,11 @@ void ReportOutput::changeEvent(QEvent *ev)
if (ev->type() == QEvent::StyleChange) {
QPalette pal = palette();
QColor color = pal.windowText().color();
unsigned long text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
unsigned int text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
unsigned long value = static_cast<unsigned long>(text);
// if this parameter is not already set use the style's window text color
text = getWindowParameter()->GetUnsigned("colorText", text);
getWindowParameter()->SetUnsigned("colorText", text);
value = getWindowParameter()->GetUnsigned("colorText", value);
getWindowParameter()->SetUnsigned("colorText", value);
}
QTextEdit::changeEvent(ev);
}

View File

@@ -273,9 +273,11 @@ void TextEditor::highlightCurrentLine()
if (!isReadOnly()) {
QTextEdit::ExtraSelection selection;
QColor lineColor = d->colormap[QLatin1String("Current line highlight")];
unsigned long col = (lineColor.red() << 24) | (lineColor.green() << 16) | (lineColor.blue() << 8);
unsigned int col = (lineColor.red() << 24) | (lineColor.green() << 16) | (lineColor.blue() << 8);
ParameterGrp::handle hPrefGrp = getWindowParameter();
col = hPrefGrp->GetUnsigned( "Current line highlight", col);
unsigned long value = static_cast<unsigned long>(col);
value = hPrefGrp->GetUnsigned( "Current line highlight", value);
col = static_cast<unsigned int>(value);
lineColor.setRgb((col>>24)&0xff, (col>>16)&0xff, (col>>8)&0xff);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
@@ -434,8 +436,10 @@ void TextEditor::OnChange(Base::Subject<const char*> &rCaller,const char* sReaso
QMap<QString, QColor>::ConstIterator it = d->colormap.find(QString::fromLatin1(sReason));
if (it != d->colormap.end()) {
QColor color = it.value();
unsigned long col = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
col = hPrefGrp->GetUnsigned( sReason, col);
unsigned int col = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8);
unsigned long value = static_cast<unsigned long>(col);
value = hPrefGrp->GetUnsigned(sReason, value);
col = static_cast<unsigned int>(value);
color.setRgb((col>>24)&0xff, (col>>16)&0xff, (col>>8)&0xff);
if (this->highlighter)
this->highlighter->setColor(QLatin1String(sReason), color);