Removing QColor (from Qt::Widgets) from core modules. (#4247)

This commit is contained in:
louib 2020-01-26 21:38:43 -05:00 committed by Jonathan White
parent 8bac8a7163
commit c8ab3b5f4f
15 changed files with 47 additions and 97 deletions

View File

@ -15,24 +15,3 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Compare.h"
#include <QColor>
bool operator<(const QColor& lhs, const QColor& rhs)
{
const QColor adaptedLhs = lhs.toCmyk();
const QColor adaptedRhs = rhs.toCmyk();
const int iCyan = compare(adaptedLhs.cyanF(), adaptedRhs.cyanF());
if (iCyan != 0) {
return iCyan;
}
const int iMagenta = compare(adaptedLhs.magentaF(), adaptedRhs.magentaF());
if (iMagenta != 0) {
return iMagenta;
}
const int iYellow = compare(adaptedLhs.yellowF(), adaptedRhs.yellowF());
if (iYellow != 0) {
return iYellow;
}
return compare(adaptedLhs.blackF(), adaptedRhs.blackF()) < 0;
}

View File

@ -34,14 +34,6 @@ enum CompareItemOption
Q_DECLARE_FLAGS(CompareItemOptions, CompareItemOption)
Q_DECLARE_OPERATORS_FOR_FLAGS(CompareItemOptions)
class QColor;
/*!
* \return true when both color match
*
* Comparison converts both into the cmyk-model
*/
bool operator<(const QColor& lhs, const QColor& rhs);
template <typename Type> inline short compareGeneric(const Type& lhs, const Type& rhs, CompareItemOptions)
{
if (lhs != rhs) {

View File

@ -208,12 +208,12 @@ const QUuid& Entry::iconUuid() const
return m_data.customIcon;
}
QColor Entry::foregroundColor() const
QString Entry::foregroundColor() const
{
return m_data.foregroundColor;
}
QColor Entry::backgroundColor() const
QString Entry::backgroundColor() const
{
return m_data.backgroundColor;
}
@ -508,14 +508,14 @@ void Entry::setIcon(const QUuid& uuid)
}
}
void Entry::setForegroundColor(const QColor& color)
void Entry::setForegroundColor(const QString& colorStr)
{
set(m_data.foregroundColor, color);
set(m_data.foregroundColor, colorStr);
}
void Entry::setBackgroundColor(const QColor& color)
void Entry::setBackgroundColor(const QString& colorStr)
{
set(m_data.backgroundColor, color);
set(m_data.backgroundColor, colorStr);
}
void Entry::setOverrideUrl(const QString& url)

View File

@ -19,7 +19,6 @@
#ifndef KEEPASSX_ENTRY_H
#define KEEPASSX_ENTRY_H
#include <QColor>
#include <QImage>
#include <QMap>
#include <QPixmap>
@ -57,8 +56,8 @@ struct EntryData
{
int iconNumber;
QUuid customIcon;
QColor foregroundColor;
QColor backgroundColor;
QString foregroundColor;
QString backgroundColor;
QString overrideUrl;
QString tags;
bool autoTypeEnabled;
@ -86,8 +85,8 @@ public:
QPixmap iconScaledPixmap() const;
int iconNumber() const;
const QUuid& iconUuid() const;
QColor foregroundColor() const;
QColor backgroundColor() const;
QString foregroundColor() const;
QString backgroundColor() const;
QString overrideUrl() const;
QString tags() const;
const TimeInfo& timeInfo() const;
@ -132,8 +131,8 @@ public:
void setUuid(const QUuid& uuid);
void setIcon(int iconNumber);
void setIcon(const QUuid& uuid);
void setForegroundColor(const QColor& color);
void setBackgroundColor(const QColor& color);
void setForegroundColor(const QString& color);
void setBackgroundColor(const QString& color);
void setOverrideUrl(const QString& url);
void setTags(const QString& tags);
void setTimeInfo(const TimeInfo& timeInfo);

View File

@ -131,7 +131,7 @@ int Metadata::maintenanceHistoryDays() const
return m_data.maintenanceHistoryDays;
}
QColor Metadata::color() const
QString Metadata::color() const
{
return m_data.color;
}
@ -347,7 +347,7 @@ void Metadata::setMaintenanceHistoryDays(int value)
set(m_data.maintenanceHistoryDays, value);
}
void Metadata::setColor(const QColor& value)
void Metadata::setColor(const QString& value)
{
set(m_data.color, value);
}

View File

@ -18,7 +18,6 @@
#ifndef KEEPASSX_METADATA_H
#define KEEPASSX_METADATA_H
#include <QColor>
#include <QDateTime>
#include <QHash>
#include <QImage>
@ -49,7 +48,7 @@ public:
QString defaultUserName;
QDateTime defaultUserNameChanged;
int maintenanceHistoryDays;
QColor color;
QString color;
bool recycleBinEnabled;
int historyMaxItems;
int historyMaxSize;
@ -72,7 +71,7 @@ public:
QDateTime defaultUserNameChanged() const;
QDateTime settingsChanged() const;
int maintenanceHistoryDays() const;
QColor color() const;
QString color() const;
bool protectTitle() const;
bool protectUsername() const;
bool protectPassword() const;
@ -113,7 +112,7 @@ public:
void setDefaultUserNameChanged(const QDateTime& value);
void setSettingsChanged(const QDateTime& value);
void setMaintenanceHistoryDays(int value);
void setColor(const QColor& value);
void setColor(const QString& value);
void setProtectTitle(bool value);
void setProtectUsername(bool value);
void setProtectPassword(bool value);

View File

@ -1047,22 +1047,21 @@ QDateTime KdbxXmlReader::readDateTime()
return Clock::currentDateTimeUtc();
}
QColor KdbxXmlReader::readColor()
QString KdbxXmlReader::readColor()
{
QString colorStr = readString();
if (colorStr.isEmpty()) {
return {};
return colorStr;
}
if (colorStr.length() != 7 || colorStr[0] != '#') {
if (m_strictMode) {
raiseError(tr("Invalid color value"));
}
return {};
return colorStr;
}
QColor color;
for (int i = 0; i <= 2; ++i) {
QString rgbPartStr = colorStr.mid(1 + 2 * i, 2);
bool ok;
@ -1071,19 +1070,11 @@ QColor KdbxXmlReader::readColor()
if (m_strictMode) {
raiseError(tr("Invalid color rgb part"));
}
return {};
}
if (i == 0) {
color.setRed(rgbPart);
} else if (i == 1) {
color.setGreen(rgbPart);
} else {
color.setBlue(rgbPart);
return colorStr;
}
}
return color;
return colorStr;
}
int KdbxXmlReader::readNumber()

View File

@ -83,7 +83,7 @@ protected:
virtual QString readString(bool& isProtected, bool& protectInMemory);
virtual bool readBool();
virtual QDateTime readDateTime();
virtual QColor readColor();
virtual QString readColor();
virtual int readNumber();
virtual QUuid readUuid();
virtual QByteArray readBinary();

View File

@ -111,7 +111,7 @@ void KdbxXmlWriter::writeMetadata()
writeString("DefaultUserName", m_meta->defaultUserName());
writeDateTime("DefaultUserNameChanged", m_meta->defaultUserNameChanged());
writeNumber("MaintenanceHistoryDays", m_meta->maintenanceHistoryDays());
writeColor("Color", m_meta->color());
writeString("Color", m_meta->color());
writeDateTime("MasterKeyChanged", m_meta->masterKeyChanged());
writeNumber("MasterKeyChangeRec", m_meta->masterKeyChangeRec());
writeNumber("MasterKeyChangeForce", m_meta->masterKeyChangeForce());
@ -346,8 +346,8 @@ void KdbxXmlWriter::writeEntry(const Entry* entry)
if (!entry->iconUuid().isNull()) {
writeUuid("CustomIconUUID", entry->iconUuid());
}
writeColor("ForegroundColor", entry->foregroundColor());
writeColor("BackgroundColor", entry->backgroundColor());
writeString("ForegroundColor", entry->foregroundColor());
writeString("BackgroundColor", entry->backgroundColor());
writeString("OverrideURL", entry->overrideUrl());
writeString("Tags", entry->tags());
writeTimes(entry->timeInfo());
@ -532,18 +532,6 @@ void KdbxXmlWriter::writeBinary(const QString& qualifiedName, const QByteArray&
writeString(qualifiedName, QString::fromLatin1(ba.toBase64()));
}
void KdbxXmlWriter::writeColor(const QString& qualifiedName, const QColor& color)
{
QString colorStr;
if (color.isValid()) {
colorStr = QString("#%1%2%3").arg(
colorPartToString(color.red()), colorPartToString(color.green()), colorPartToString(color.blue()));
}
writeString(qualifiedName, colorStr);
}
void KdbxXmlWriter::writeTriState(const QString& qualifiedName, Group::TriState triState)
{
QString value;

View File

@ -18,7 +18,6 @@
#ifndef KEEPASSX_KDBXXMLWRITER_H
#define KEEPASSX_KDBXXMLWRITER_H
#include <QColor>
#include <QDateTime>
#include <QImage>
#include <QXmlStreamWriter>
@ -74,7 +73,6 @@ private:
void writeUuid(const QString& qualifiedName, const Group* group);
void writeUuid(const QString& qualifiedName, const Entry* entry);
void writeBinary(const QString& qualifiedName, const QByteArray& ba);
void writeColor(const QString& qualifiedName, const QColor& color);
void writeTriState(const QString& qualifiedName, Group::TriState triState);
QString colorPartToString(int value);
QString stripInvalidXml10Chars(QString str);

View File

@ -1123,15 +1123,15 @@ void EditEntryWidget::updateEntryData(Entry* entry) const
entry->setNotes(m_mainUi->notesEdit->toPlainText());
if (m_advancedUi->fgColorCheckBox->isChecked() && m_advancedUi->fgColorButton->property("color").isValid()) {
entry->setForegroundColor(QColor(m_advancedUi->fgColorButton->property("color").toString()));
entry->setForegroundColor(m_advancedUi->fgColorButton->property("color").toString());
} else {
entry->setForegroundColor(QColor());
entry->setForegroundColor(QString());
}
if (m_advancedUi->bgColorCheckBox->isChecked() && m_advancedUi->bgColorButton->property("color").isValid()) {
entry->setBackgroundColor(QColor(m_advancedUi->bgColorButton->property("color").toString()));
entry->setBackgroundColor(m_advancedUi->bgColorButton->property("color").toString());
} else {
entry->setBackgroundColor(QColor());
entry->setBackgroundColor(QString());
}
IconStruct iconStruct = m_iconsWidget->state();

View File

@ -271,6 +271,8 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
}
return font;
} else if (role == Qt::ForegroundRole) {
QColor foregroundColor;
foregroundColor.setNamedColor(entry->foregroundColor());
if (entry->hasReferences()) {
QPalette p;
#ifdef Q_OS_MACOS
@ -279,12 +281,14 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
}
#endif
return QVariant(p.color(QPalette::Active, QPalette::Mid));
} else if (entry->foregroundColor().isValid()) {
return QVariant(entry->foregroundColor());
} else if (foregroundColor.isValid()) {
return QVariant(foregroundColor);
}
} else if (role == Qt::BackgroundRole) {
if (entry->backgroundColor().isValid()) {
return QVariant(entry->backgroundColor());
QColor backgroundColor;
backgroundColor.setNamedColor(entry->backgroundColor());
if (backgroundColor.isValid()) {
return QVariant(backgroundColor);
}
} else if (role == Qt::TextAlignmentRole) {
if (index.column() == Paperclip) {

View File

@ -86,7 +86,7 @@ void TestKeePass2Format::testXmlMetadata()
QCOMPARE(m_xmlDb->metadata()->defaultUserName(), QString("DEFUSERNAME"));
QCOMPARE(m_xmlDb->metadata()->defaultUserNameChanged(), MockClock::datetimeUtc(2010, 8, 8, 17, 27, 45));
QCOMPARE(m_xmlDb->metadata()->maintenanceHistoryDays(), 127);
QCOMPARE(m_xmlDb->metadata()->color(), QColor(0xff, 0xef, 0x00));
QCOMPARE(m_xmlDb->metadata()->color(), QString("#FFEF00"));
QCOMPARE(m_xmlDb->metadata()->masterKeyChanged(), MockClock::datetimeUtc(2012, 4, 5, 17, 9, 34));
QCOMPARE(m_xmlDb->metadata()->masterKeyChangeRec(), 101);
QCOMPARE(m_xmlDb->metadata()->masterKeyChangeForce(), -1);
@ -200,8 +200,8 @@ void TestKeePass2Format::testXmlEntry1()
QCOMPARE(entry->historyItems().size(), 2);
QCOMPARE(entry->iconNumber(), 0);
QCOMPARE(entry->iconUuid(), QUuid());
QVERIFY(!entry->foregroundColor().isValid());
QVERIFY(!entry->backgroundColor().isValid());
QVERIFY(entry->foregroundColor().isEmpty());
QVERIFY(entry->backgroundColor().isEmpty());
QCOMPARE(entry->overrideUrl(), QString(""));
QCOMPARE(entry->tags(), QString("a b c"));
@ -262,8 +262,8 @@ void TestKeePass2Format::testXmlEntry2()
QCOMPARE(entry->iconNumber(), 0);
QCOMPARE(entry->iconUuid(), QUuid::fromRfc4122(QByteArray::fromBase64("++vyI+daLk6omox4a6kQGA==")));
// TODO: test entry->icon()
QCOMPARE(entry->foregroundColor(), QColor(255, 0, 0));
QCOMPARE(entry->backgroundColor(), QColor(255, 255, 0));
QCOMPARE(entry->foregroundColor(), QString("#FF0000"));
QCOMPARE(entry->backgroundColor(), QString("#FFFF00"));
QCOMPARE(entry->overrideUrl(), QString("http://override.net/"));
QCOMPARE(entry->tags(), QString(""));

View File

@ -309,13 +309,13 @@ void TestModified::testEntrySets()
entry->setDefaultAutoTypeSequence(entry->defaultAutoTypeSequence());
QTRY_COMPARE(spyModified.count(), spyCount);
entry->setForegroundColor(Qt::red);
entry->setForegroundColor(QString("#FF0000"));
++spyCount;
QTRY_COMPARE(spyModified.count(), spyCount);
entry->setForegroundColor(entry->foregroundColor());
QTRY_COMPARE(spyModified.count(), spyCount);
entry->setBackgroundColor(Qt::red);
entry->setBackgroundColor(QString("#FF0000"));
++spyCount;
QTRY_COMPARE(spyModified.count(), spyCount);
entry->setBackgroundColor(entry->backgroundColor());

View File

@ -432,8 +432,8 @@ void TestGui::testEditEntry()
// Test entry colors (simulate choosing a color)
editEntryWidget->setCurrentPage(1);
auto fgColor = QColor(Qt::red);
auto bgColor = QColor(Qt::blue);
auto fgColor = QString("#FF0000");
auto bgColor = QString("#0000FF");
// Set foreground color
auto colorButton = editEntryWidget->findChild<QPushButton*>("fgColorButton");
auto colorCheckBox = editEntryWidget->findChild<QCheckBox*>("fgColorCheckBox");