Move key generate logic from Format to FontData/FillData/...
This commit is contained in:
+15
-48
@@ -232,20 +232,19 @@ void Format::setFontName(const QString &name)
|
|||||||
bool Format::fontIndexValid() const
|
bool Format::fontIndexValid() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
return !d->fontData._dirty && d->fontData._indexValid;
|
return d->fontData.indexValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Format::fontIndex() const
|
int Format::fontIndex() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
return d->fontData._index;
|
return d->fontData.index();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Format::setFontIndex(int index)
|
void Format::setFontIndex(int index)
|
||||||
{
|
{
|
||||||
Q_D(Format);
|
Q_D(Format);
|
||||||
d->fontData._index = index;
|
d->fontData.setIndex(index);
|
||||||
d->fontData._indexValid = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Format::fontFamily() const
|
int Format::fontFamily() const
|
||||||
@@ -271,21 +270,9 @@ QString Format::fontScheme() const
|
|||||||
QByteArray Format::fontKey() const
|
QByteArray Format::fontKey() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
if (d->fontData._dirty) {
|
if (d->fontData._dirty)
|
||||||
QByteArray key;
|
|
||||||
QDataStream stream(&key, QIODevice::WriteOnly);
|
|
||||||
stream<<d->fontData.bold<<d->fontData.charset<<d->fontData.color<<d->fontData.condense
|
|
||||||
<<d->fontData.extend<<d->fontData.family<<d->fontData.italic<<d->fontData.name
|
|
||||||
<<d->fontData.outline<<d->fontData.scheme<<d->fontData.scirpt<<d->fontData.shadow
|
|
||||||
<<d->fontData.size<<d->fontData.strikeOut<<d->fontData.underline;
|
|
||||||
|
|
||||||
const_cast<FormatPrivate*>(d)->fontData._key = key;
|
|
||||||
const_cast<FormatPrivate*>(d)->fontData._dirty = false;
|
|
||||||
const_cast<FormatPrivate*>(d)->fontData._indexValid = false; //must re-assign a new index
|
|
||||||
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated.
|
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated.
|
||||||
}
|
return d->fontData.key();
|
||||||
|
|
||||||
return d->fontData._key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Format::HorizontalAlignment Format::horizontalAlignment() const
|
Format::HorizontalAlignment Format::horizontalAlignment() const
|
||||||
@@ -621,20 +608,19 @@ void Format::setDiagonalBorderColor(const QColor &color)
|
|||||||
bool Format::borderIndexValid() const
|
bool Format::borderIndexValid() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
return !d->borderData._dirty && d->borderData._indexValid;
|
return d->borderData.indexValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Format::borderIndex() const
|
int Format::borderIndex() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
return d->borderData._index;
|
return d->borderData.index();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Format::setBorderIndex(int index)
|
void Format::setBorderIndex(int index)
|
||||||
{
|
{
|
||||||
Q_D(Format);
|
Q_D(Format);
|
||||||
d->borderData._index = index;
|
d->borderData.setIndex(index);
|
||||||
d->borderData._indexValid = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Internal
|
/* Internal
|
||||||
@@ -642,21 +628,10 @@ void Format::setBorderIndex(int index)
|
|||||||
QByteArray Format::borderKey() const
|
QByteArray Format::borderKey() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
if (d->borderData._dirty) {
|
if (d->borderData._dirty)
|
||||||
QByteArray key;
|
|
||||||
QDataStream stream(&key, QIODevice::WriteOnly);
|
|
||||||
stream<<d->borderData.bottom<<d->borderData.bottomColor
|
|
||||||
<<d->borderData.diagonal<<d->borderData.diagonalColor<<d->borderData.diagonalType
|
|
||||||
<<d->borderData.left<<d->borderData.leftColor
|
|
||||||
<<d->borderData.right<<d->borderData.rightColor
|
|
||||||
<<d->borderData.top<<d->borderData.topColor;
|
|
||||||
const_cast<FormatPrivate*>(d)->borderData._key = key;
|
|
||||||
const_cast<FormatPrivate*>(d)->borderData._dirty = false;
|
|
||||||
const_cast<FormatPrivate*>(d)->borderData._indexValid = false;
|
|
||||||
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated.
|
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated.
|
||||||
}
|
|
||||||
|
|
||||||
return d->borderData._key;
|
return d->borderData.key();
|
||||||
}
|
}
|
||||||
|
|
||||||
Format::FillPattern Format::fillPattern() const
|
Format::FillPattern Format::fillPattern() const
|
||||||
@@ -705,20 +680,19 @@ void Format::setPatternBackgroundColor(const QColor &color)
|
|||||||
bool Format::fillIndexValid() const
|
bool Format::fillIndexValid() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
return !d->fillData._dirty && d->fillData._indexValid;
|
return d->fillData.indexValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Format::fillIndex() const
|
int Format::fillIndex() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
return d->fillData._index;
|
return d->fillData.index();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Format::setFillIndex(int index)
|
void Format::setFillIndex(int index)
|
||||||
{
|
{
|
||||||
Q_D(Format);
|
Q_D(Format);
|
||||||
d->fillData._index = index;
|
d->fillData.setIndex(index);
|
||||||
d->fillData._indexValid = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Internal
|
/* Internal
|
||||||
@@ -726,17 +700,10 @@ void Format::setFillIndex(int index)
|
|||||||
QByteArray Format::fillKey() const
|
QByteArray Format::fillKey() const
|
||||||
{
|
{
|
||||||
Q_D(const Format);
|
Q_D(const Format);
|
||||||
if (d->fillData._dirty) {
|
if (d->fillData._dirty)
|
||||||
QByteArray key;
|
|
||||||
QDataStream stream(&key, QIODevice::WriteOnly);
|
|
||||||
stream<<d->fillData.bgColor<<d->fillData.fgColor<<d->fillData.pattern;
|
|
||||||
const_cast<FormatPrivate*>(d)->fillData._key = key;
|
|
||||||
const_cast<FormatPrivate*>(d)->fillData._dirty = false;
|
|
||||||
const_cast<FormatPrivate*>(d)->fillData._indexValid = false;
|
|
||||||
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated.
|
const_cast<FormatPrivate*>(d)->dirty = true; //Make sure formatKey() will be re-generated.
|
||||||
}
|
|
||||||
|
|
||||||
return d->fillData._key;
|
return d->fillData.key();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Format::hidden() const
|
bool Format::hidden() const
|
||||||
|
|||||||
+102
-3
@@ -65,8 +65,43 @@ struct FontData
|
|||||||
int condense;
|
int condense;
|
||||||
int extend;
|
int extend;
|
||||||
|
|
||||||
|
QByteArray key() const
|
||||||
|
{
|
||||||
|
if (_dirty) {
|
||||||
|
QByteArray key;
|
||||||
|
QDataStream stream(&key, QIODevice::WriteOnly);
|
||||||
|
stream<<bold<<charset<<color<<condense
|
||||||
|
<<extend<<family<<italic<<name
|
||||||
|
<<outline<<scheme<<scirpt<<shadow
|
||||||
|
<<size<<strikeOut<<underline;
|
||||||
|
|
||||||
|
const_cast<FontData*>(this)->_key = key;
|
||||||
|
const_cast<FontData*>(this)->_dirty = false;
|
||||||
|
const_cast<FontData*>(this)->_indexValid = false;//dirty flag can not be simply cleared.
|
||||||
|
}
|
||||||
|
return _key;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool indexValid() const
|
||||||
|
{
|
||||||
|
return !_dirty && _indexValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index() const
|
||||||
|
{
|
||||||
|
return _index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIndex(int index)
|
||||||
|
{
|
||||||
|
_index = index;
|
||||||
|
_indexValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
//helper member
|
//helper member
|
||||||
bool _dirty; //key re-generated is need.
|
bool _dirty; //key re-generated and proper index assign is need.
|
||||||
|
|
||||||
|
private:
|
||||||
QByteArray _key;
|
QByteArray _key;
|
||||||
bool _indexValid; //has a valid index, so no need to assign a new one
|
bool _indexValid; //has a valid index, so no need to assign a new one
|
||||||
int _index; //index in the Font list
|
int _index; //index in the Font list
|
||||||
@@ -108,8 +143,41 @@ struct BorderData
|
|||||||
QColor diagonalColor;
|
QColor diagonalColor;
|
||||||
Format::DiagonalBorderType diagonalType;
|
Format::DiagonalBorderType diagonalType;
|
||||||
|
|
||||||
|
QByteArray key() const
|
||||||
|
{
|
||||||
|
if (_dirty) {
|
||||||
|
QByteArray key;
|
||||||
|
QDataStream stream(&key, QIODevice::WriteOnly);
|
||||||
|
stream << bottom << bottomColor << top << topColor
|
||||||
|
<< diagonal << diagonalColor << diagonalType
|
||||||
|
<< left << leftColor << right << rightColor;
|
||||||
|
const_cast<BorderData*>(this)->_key = key;
|
||||||
|
const_cast<BorderData*>(this)->_dirty = false;
|
||||||
|
const_cast<BorderData*>(this)->_indexValid = false;
|
||||||
|
}
|
||||||
|
return _key;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool indexValid() const
|
||||||
|
{
|
||||||
|
return !_dirty && _indexValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index() const
|
||||||
|
{
|
||||||
|
return _index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIndex(int index)
|
||||||
|
{
|
||||||
|
_index = index;
|
||||||
|
_indexValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
//helper member
|
//helper member
|
||||||
bool _dirty; //key re-generated is need.
|
bool _dirty; //key re-generated and proper index assign is need.
|
||||||
|
|
||||||
|
private:
|
||||||
QByteArray _key;
|
QByteArray _key;
|
||||||
bool _indexValid; //has a valid index, so no need to assign a new one
|
bool _indexValid; //has a valid index, so no need to assign a new one
|
||||||
int _index; //index in the border list
|
int _index; //index in the border list
|
||||||
@@ -125,8 +193,39 @@ struct FillData {
|
|||||||
QColor bgColor;
|
QColor bgColor;
|
||||||
QColor fgColor;
|
QColor fgColor;
|
||||||
|
|
||||||
|
QByteArray key() const
|
||||||
|
{
|
||||||
|
if (_dirty) {
|
||||||
|
QByteArray key;
|
||||||
|
QDataStream stream(&key, QIODevice::WriteOnly);
|
||||||
|
stream<<bgColor<<fgColor<<pattern;
|
||||||
|
const_cast<FillData*>(this)->_key = key;
|
||||||
|
const_cast<FillData*>(this)->_dirty = false;
|
||||||
|
const_cast<FillData*>(this)->_indexValid = false;
|
||||||
|
}
|
||||||
|
return _key;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool indexValid() const
|
||||||
|
{
|
||||||
|
return !_dirty && _indexValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index() const
|
||||||
|
{
|
||||||
|
return _index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIndex(int index)
|
||||||
|
{
|
||||||
|
_index = index;
|
||||||
|
_indexValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
//helper member
|
//helper member
|
||||||
bool _dirty; //key re-generated is need.
|
bool _dirty; //key re-generated and proper index assign is need.
|
||||||
|
|
||||||
|
private:
|
||||||
QByteArray _key;
|
QByteArray _key;
|
||||||
bool _indexValid; //has a valid index, so no need to assign a new one
|
bool _indexValid; //has a valid index, so no need to assign a new one
|
||||||
int _index; //index in the border list
|
int _index; //index in the border list
|
||||||
|
|||||||
+10
-10
@@ -42,7 +42,7 @@ Styles::Styles()
|
|||||||
QSharedPointer<FillData> fill = QSharedPointer<FillData>(new FillData);
|
QSharedPointer<FillData> fill = QSharedPointer<FillData>(new FillData);
|
||||||
fill->pattern = Format::PatternGray125;
|
fill->pattern = Format::PatternGray125;
|
||||||
m_fillsList.append(fill);
|
m_fillsList.append(fill);
|
||||||
m_fillsHash[fill->_key] = fill;
|
m_fillsHash[fill->key()] = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
Styles::~Styles()
|
Styles::~Styles()
|
||||||
@@ -124,33 +124,33 @@ void Styles::addFormat(Format *format)
|
|||||||
if (!format->fontIndexValid()) {
|
if (!format->fontIndexValid()) {
|
||||||
if (!m_fontsHash.contains(format->fontKey())) {
|
if (!m_fontsHash.contains(format->fontKey())) {
|
||||||
QSharedPointer<FontData> font = QSharedPointer<FontData>(new FontData(format->d_func()->fontData));
|
QSharedPointer<FontData> font = QSharedPointer<FontData>(new FontData(format->d_func()->fontData));
|
||||||
font->_index = m_fontsList.size(); //Assign proper index
|
font->setIndex(m_fontsList.size()); //Assign proper index
|
||||||
m_fontsList.append(font);
|
m_fontsList.append(font);
|
||||||
m_fontsHash[font->_key] = font;
|
m_fontsHash[font->key()] = font;
|
||||||
}
|
}
|
||||||
format->setFontIndex(m_fontsHash[format->fontKey()]->_index);
|
format->setFontIndex(m_fontsHash[format->fontKey()]->index());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fill
|
//Fill
|
||||||
if (!format->fillIndexValid()) {
|
if (!format->fillIndexValid()) {
|
||||||
if (!m_fillsHash.contains(format->fillKey())) {
|
if (!m_fillsHash.contains(format->fillKey())) {
|
||||||
QSharedPointer<FillData> fill = QSharedPointer<FillData>(new FillData(format->d_func()->fillData));
|
QSharedPointer<FillData> fill = QSharedPointer<FillData>(new FillData(format->d_func()->fillData));
|
||||||
fill->_index = m_fillsList.size(); //Assign proper index
|
fill->setIndex(m_fillsList.size()); //Assign proper index
|
||||||
m_fillsList.append(fill);
|
m_fillsList.append(fill);
|
||||||
m_fillsHash[fill->_key] = fill;
|
m_fillsHash[fill->key()] = fill;
|
||||||
}
|
}
|
||||||
format->setFillIndex(m_fillsHash[format->fillKey()]->_index);
|
format->setFillIndex(m_fillsHash[format->fillKey()]->index());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Border
|
//Border
|
||||||
if (!format->borderIndexValid()) {
|
if (!format->borderIndexValid()) {
|
||||||
if (!m_bordersHash.contains(format->borderKey())) {
|
if (!m_bordersHash.contains(format->borderKey())) {
|
||||||
QSharedPointer<BorderData> border = QSharedPointer<BorderData>(new BorderData(format->d_func()->borderData));
|
QSharedPointer<BorderData> border = QSharedPointer<BorderData>(new BorderData(format->d_func()->borderData));
|
||||||
border->_index = m_bordersList.size(); //Assign proper index
|
border->setIndex(m_bordersList.size()); //Assign proper index
|
||||||
m_bordersList.append(border);
|
m_bordersList.append(border);
|
||||||
m_bordersHash[border->_key] = border;
|
m_bordersHash[border->key()] = border;
|
||||||
}
|
}
|
||||||
format->setBorderIndex(m_bordersHash[format->borderKey()]->_index);
|
format->setBorderIndex(m_bordersHash[format->borderKey()]->index());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Format
|
//Format
|
||||||
|
|||||||
Reference in New Issue
Block a user