r21374 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Sun Jun 12 23:57:30 UTC 2016
Author: jghali
Date: Sun Jun 12 23:57:30 2016
New Revision: 21374
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21374
Log:
#14129: fix crash caused by incorrect handling of references to deleted styles by style manager
Modified:
trunk/Scribus/scribus/scribus.cpp
trunk/Scribus/scribus/style.h
trunk/Scribus/scribus/styles/style.cpp
trunk/Scribus/scribus/ui/smcellstyle.cpp
trunk/Scribus/scribus/ui/smtablestyle.cpp
trunk/Scribus/scribus/ui/smtextstyles.cpp
trunk/Scribus/scribus/ui/smtextstyles.h
Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21374&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Sun Jun 12 23:57:30 2016
@@ -683,7 +683,7 @@
// initializing style manager here too even it's not strictly a palette
m_styleManager = new StyleManager(this, "styleManager");
SMCharacterStyle *tmpCS = new SMCharacterStyle();
- m_styleManager->addStyle(new SMParagraphStyle(tmpCS->tmpStyles()));
+ m_styleManager->addStyle(new SMParagraphStyle(tmpCS));
m_styleManager->addStyle(tmpCS);
m_styleManager->addStyle(new SMTableStyle());
m_styleManager->addStyle(new SMCellStyle());
Modified: trunk/Scribus/scribus/style.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21374&path=/trunk/Scribus/scribus/style.h
==============================================================================
--- trunk/Scribus/scribus/style.h (original)
+++ trunk/Scribus/scribus/style.h Sun Jun 12 23:57:30 2016
@@ -95,6 +95,8 @@
void setParent(const QString& p);
bool hasParent() const { return ! m_parent.isEmpty(); }
const Style* parentStyle() const;
+
+ bool canInherit(const QString& parentName) const;
static const QString INHERIT_PARENT;
Modified: trunk/Scribus/scribus/styles/style.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21374&path=/trunk/Scribus/scribus/styles/style.cpp
==============================================================================
--- trunk/Scribus/scribus/styles/style.cpp (original)
+++ trunk/Scribus/scribus/styles/style.cpp Sun Jun 12 23:57:30 2016
@@ -68,6 +68,32 @@
if (par == this) return NULL; else return par;
}
+bool Style::canInherit(const QString& parentName) const
+{
+ if (m_name.isEmpty() || parentName.isEmpty())
+ return true;
+ if (!m_context || (m_name == parentName))
+ return false;
+
+ const Style* parentStyle = m_context->resolve(parentName);
+ if (!parentStyle)
+ return false;
+
+ bool loop = false, parentLoop = false;
+
+ const Style* pStyle = parentStyle;
+ while (pStyle)
+ {
+ if (pStyle->hasParent() && (pStyle->parent() == m_name))
+ {
+ loop = parentLoop = true;
+ break;
+ }
+ pStyle = pStyle->hasParent() ? pStyle->parentStyle() : NULL;
+ }
+
+ return (!parentLoop);
+}
void Style::saxxAttributes(Xml_attr& attr) const
{
Modified: trunk/Scribus/scribus/ui/smcellstyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21374&path=/trunk/Scribus/scribus/ui/smcellstyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smcellstyle.cpp (original)
+++ trunk/Scribus/scribus/ui/smcellstyle.cpp Sun Jun 12 23:57:30 2016
@@ -292,6 +292,35 @@
if (index > -1)
m_cachedStyles.remove(index);
m_deleted << removeItem;
+ }
+
+ // Check other styles and replace inherited styles if necessary
+ for (int i = 0; i < m_cachedStyles.count(); ++i)
+ {
+ CellStyle& cellStyle = m_cachedStyles[i];
+ QString parentName = cellStyle.parent();
+ if (parentName.isEmpty())
+ continue;
+
+ QString replacementName = parentName;
+ for (int j = 0; j < removeList.count(); ++j)
+ {
+ if (removeList.at(j).first == parentName)
+ {
+ replacementName = removeList.at(j).second;
+ break;
+ }
+ }
+
+ if (replacementName == parentName)
+ continue;
+ if (replacementName == CommonStrings::trDefaultCellStyle)
+ replacementName = CommonStrings::DefaultCellStyle;
+ if (!cellStyle.canInherit(replacementName))
+ replacementName = QString();
+ if (!replacementName.isEmpty() && (m_cachedStyles.find(replacementName) < 0))
+ replacementName = QString();
+ cellStyle.setParent(replacementName);
}
}
Modified: trunk/Scribus/scribus/ui/smtablestyle.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21374&path=/trunk/Scribus/scribus/ui/smtablestyle.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smtablestyle.cpp (original)
+++ trunk/Scribus/scribus/ui/smtablestyle.cpp Sun Jun 12 23:57:30 2016
@@ -288,6 +288,35 @@
if (index > -1)
m_cachedStyles.remove(index);
m_deleted << removeItem;
+ }
+
+ // Check other styles and replace inherited styles if necessary
+ for (int i = 0; i < m_cachedStyles.count(); ++i)
+ {
+ TableStyle& tableStyle = m_cachedStyles[i];
+ QString parentName = tableStyle.parent();
+ if (parentName.isEmpty())
+ continue;
+
+ QString replacementName = parentName;
+ for (int j = 0; j < removeList.count(); ++j)
+ {
+ if (removeList.at(j).first == parentName)
+ {
+ replacementName = removeList.at(j).second;
+ break;
+ }
+ }
+
+ if (replacementName == parentName)
+ continue;
+ if (replacementName == CommonStrings::trDefaultTableStyle)
+ replacementName = CommonStrings::DefaultTableStyle;
+ if (!tableStyle.canInherit(replacementName))
+ replacementName = QString();
+ if (!replacementName.isEmpty() && (m_cachedStyles.find(replacementName) < 0))
+ replacementName = QString();
+ tableStyle.setParent(replacementName);
}
}
Modified: trunk/Scribus/scribus/ui/smtextstyles.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21374&path=/trunk/Scribus/scribus/ui/smtextstyles.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/smtextstyles.cpp (original)
+++ trunk/Scribus/scribus/ui/smtextstyles.cpp Sun Jun 12 23:57:30 2016
@@ -41,10 +41,11 @@
#include "util.h"
-SMParagraphStyle::SMParagraphStyle(StyleSet<CharStyle> *cstyles) : StyleItem(),
-m_pwidget(0), m_doc(0), m_selectionIsDirty(false), m_unitRatio(1.0), m_cstyles(cstyles)
-{
- Q_ASSERT(m_cstyles);
+SMParagraphStyle::SMParagraphStyle(SMCharacterStyle* cstyleItem) : StyleItem(),
+m_pwidget(0), m_doc(0), m_selectionIsDirty(false), m_unitRatio(1.0), m_cstyleItem(cstyleItem)
+{
+ Q_ASSERT(m_cstyleItem);
+ m_cstyles = m_cstyleItem->tmpStyles();
m_pwidget = new SMPStyleWidget(m_doc, m_cstyles);
Q_CHECK_PTR(m_pwidget);
}
@@ -404,6 +405,35 @@
m_tmpStyles.remove(index);
m_deleted.append(removeList[i]);
+ }
+
+ // Check other paragraph styles and replace inherited styles if necessary
+ for (int i = 0; i < m_tmpStyles.count(); ++i)
+ {
+ ParagraphStyle& parStyle = m_tmpStyles[i];
+ QString parentName = parStyle.parent();
+ if (parentName.isEmpty())
+ continue;
+
+ QString replacementName = parentName;
+ for (int j = 0; j < removeList.count(); ++j)
+ {
+ if (removeList.at(j).first == parentName)
+ {
+ replacementName = removeList.at(j).second;
+ break;
+ }
+ }
+
+ if (replacementName == parentName)
+ continue;
+ if (replacementName == CommonStrings::trDefaultParagraphStyle)
+ replacementName = CommonStrings::DefaultParagraphStyle;
+ if (!parStyle.canInherit(replacementName))
+ replacementName = QString();
+ if (!replacementName.isEmpty() && (m_tmpStyles.find(replacementName) < 0))
+ replacementName = QString();
+ parStyle.setParent(replacementName);
}
}
@@ -572,6 +602,9 @@
connect(m_pwidget->cpage->parentCombo, SIGNAL(activated(const QString&)), this, SLOT(slotCharParentChanged(const QString&)));
connect(m_pwidget->cpage->backColor_, SIGNAL(activated(const QString&)), this, SLOT(slotBackColor()));
connect(m_pwidget->cpage->backShade_, SIGNAL(clicked()), this, SLOT(slotBackShade()));
+
+ // Referenced character style changes
+ connect(m_cstyleItem, SIGNAL(charStylesDeleted(const QList<RemoveItem>&)), this, SLOT(slotCharStylesDeleted(const QList<RemoveItem>&)));
}
void SMParagraphStyle::removeConnections()
@@ -658,6 +691,8 @@
disconnect(m_pwidget->cpage->parentCombo, SIGNAL(activated(const QString&)), this, SLOT(slotCharParentChanged(const QString&)));
disconnect(m_pwidget->cpage->backColor_, SIGNAL(activated(const QString&)), this, SLOT(slotBackColor()));
disconnect(m_pwidget->cpage->backShade_, SIGNAL(clicked()), this, SLOT(slotBackShade()));
+
+ disconnect(m_cstyleItem, SIGNAL(charStylesDeleted(const QList<RemoveItem>&)), this, SLOT(slotCharStylesDeleted(const QList<RemoveItem>&)));
}
void SMParagraphStyle::slotLineSpacingMode(int mode)
@@ -1894,6 +1929,48 @@
}
}
+void SMParagraphStyle::slotCharStylesDeleted(const QList<RemoveItem> &removeList)
+{
+ for (int i = 0; i < m_tmpStyles.count(); ++i)
+ {
+ ParagraphStyle& parStyle = m_tmpStyles[i];
+
+ QString charStyleName = parStyle.charStyle().parent();
+ if (!charStyleName.isEmpty())
+ {
+ for (int j = 0; j < removeList.count(); ++j)
+ {
+ const RemoveItem& rmItem = removeList.at(j);
+ if (charStyleName == rmItem.first)
+ {
+ QString replacementName = rmItem.second;
+ if (rmItem.second == CommonStrings::trDefaultCharacterStyle)
+ replacementName = CommonStrings::DefaultCharacterStyle;
+ parStyle.charStyle().setParent(replacementName);
+ break;
+ }
+ }
+ }
+
+ QString peCharStyleName = parStyle.peCharStyleName();
+ if (!peCharStyleName.isEmpty())
+ {
+ for (int j = 0; j < removeList.count(); ++j)
+ {
+ const RemoveItem& rmItem = removeList.at(j);
+ if (peCharStyleName == rmItem.first)
+ {
+ QString replacementName = rmItem.second;
+ if (rmItem.second == CommonStrings::trDefaultCharacterStyle)
+ replacementName = CommonStrings::DefaultCharacterStyle;
+ parStyle.setPeCharStyleName(replacementName);
+ break;
+ }
+ }
+ }
+ }
+}
+
SMParagraphStyle::~SMParagraphStyle()
{
delete m_pwidget;
@@ -2232,6 +2309,37 @@
m_tmpStyles.remove(index);
m_deleted << removeList[i];
}
+
+ // Check other character styles and replace inherited styles if necessary
+ for (int i = 0; i < m_tmpStyles.count(); ++i)
+ {
+ CharStyle& charStyle = m_tmpStyles[i];
+ QString parentName = charStyle.parent();
+ if (parentName.isEmpty())
+ continue;
+
+ QString replacementName = parentName;
+ for (int j = 0; j < removeList.count(); ++j)
+ {
+ if (removeList.at(j).first == parentName)
+ {
+ replacementName = removeList.at(j).second;
+ break;
+ }
+ }
+
+ if (replacementName == parentName)
+ continue;
+ if (replacementName == CommonStrings::trDefaultCharacterStyle)
+ replacementName = CommonStrings::DefaultCharacterStyle;
+ if (!charStyle.canInherit(replacementName))
+ replacementName = QString();
+ if (!replacementName.isEmpty() && (m_tmpStyles.find(replacementName) < 0))
+ replacementName = QString();
+ charStyle.setParent(replacementName);
+ }
+
+ emit charStylesDeleted(removeList);
}
void SMCharacterStyle::nameChanged(const QString &newName)
@@ -2273,7 +2381,12 @@
}
if (oldName != newName)
+ {
m_deleted.append(RemoveItem(oldName, newName));
+ QList<RemoveItem> deletedStyles;
+ deletedStyles.append(RemoveItem(oldName, newName));
+ emit charStylesDeleted(deletedStyles);
+ }
if (!m_selectionIsDirty)
{
Modified: trunk/Scribus/scribus/ui/smtextstyles.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21374&path=/trunk/Scribus/scribus/ui/smtextstyles.h
==============================================================================
--- trunk/Scribus/scribus/ui/smtextstyles.h (original)
+++ trunk/Scribus/scribus/ui/smtextstyles.h Sun Jun 12 23:57:30 2016
@@ -16,12 +16,13 @@
class ScribusDoc;
class SMCStyleWidget;
class SMPStyleWidget;
+class SMCharacterStyle;
class SMParagraphStyle : public StyleItem
{
Q_OBJECT
public:
- SMParagraphStyle(StyleSet<CharStyle> *cstyles);
+ SMParagraphStyle(SMCharacterStyle* cstyleItem);
~SMParagraphStyle();
QTabWidget* widget();
@@ -53,6 +54,7 @@
private:
SMPStyleWidget *m_pwidget;
+ SMCharacterStyle* m_cstyleItem;
ScribusDoc *m_doc;
bool m_selectionIsDirty;
double m_unitRatio;
@@ -129,6 +131,7 @@
void slotFont(QString s);
void slotParentChanged(const QString &parent);
void slotCharParentChanged(const QString &parent);
+ void slotCharStylesDeleted(const QList<RemoveItem> &removeList);
};
class SMCharacterStyle : public StyleItem
@@ -164,6 +167,7 @@
signals:
void selectionDirty();
+ void charStylesDeleted(const QList<RemoveItem> &removeList);
private:
QTabWidget *m_widget;
More information about the scribus-commit
mailing list