[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra] /: Fix crash in Krita on the new styles combo
From: Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date: 2013-02-13 17:53:02
Message-ID: 20130213175302.D3AE7A60C8 () git ! kde ! org
[Download RAW message or body]
Git commit 9b0e48951612e87322ec9cad27bb82f7da05bf49 by Pierre Stirnweiss.
Committed on 21/01/2013 at 20:19.
Pushed by pstirnweiss into branch 'master'.
Fix crash in Krita on the new styles combo
In Krita, there is no style loaded from a file. Instead, Krita is using
the default paragraph style. The new styles combo used to hide this
style.
This patch creates a default set of styles for these type of
applications. Also the default style is not hidden in the combo.
REVIEW: 108532
BUG: 313414
Cherry-picked from textshape-stylesWidget-PierreSt
Conflicts:
plugins/textshape/dialogs/DockerStylesComboModel.cpp
M +4 -0 libs/kotext/opendocument/KoTextSharedLoadingData.cpp
M +77 -16 libs/kotext/styles/KoStyleManager.cpp
M +14 -0 libs/kotext/styles/KoStyleManager.h
M +3 -1 plugins/textshape/TextShapeFactory.cpp
M +9 -6 plugins/textshape/dialogs/DockerStylesComboModel.cpp
M +1 -1 plugins/textshape/dialogs/StylesModel.cpp
http://commits.kde.org/calligra/9b0e48951612e87322ec9cad27bb82f7da05bf49
diff --git a/libs/kotext/opendocument/KoTextSharedLoadingData.cpp \
b/libs/kotext/opendocument/KoTextSharedLoadingData.cpp index dc797ed..a8b6d9c 100644
--- a/libs/kotext/opendocument/KoTextSharedLoadingData.cpp
+++ b/libs/kotext/opendocument/KoTextSharedLoadingData.cpp
@@ -145,6 +145,10 @@ void \
KoTextSharedLoadingData::addDefaultParagraphStyle(KoShapeLoadingContext &co
void KoTextSharedLoadingData::loadOdfStyles(KoShapeLoadingContext &shapeContext, \
KoStyleManager *styleManager) {
+ if (styleManager) {
+ styleManager->useLoadedStyles();
+ }
+
KoOdfLoadingContext &context = shapeContext.odfLoadingContext();
// only add styles of office:styles to the style manager
diff --git a/libs/kotext/styles/KoStyleManager.cpp \
b/libs/kotext/styles/KoStyleManager.cpp index c2a64e9..4110284 100644
--- a/libs/kotext/styles/KoStyleManager.cpp
+++ b/libs/kotext/styles/KoStyleManager.cpp
@@ -57,7 +57,7 @@
class KoStyleManager::Private
{
public:
- Private() : defaultCharacterStyle(0), defaultParagraphStyle(0), \
defaultListStyle(0), defaultOutlineStyle(0), outlineStyle(0), undoStack(0), \
changeCommand(0) + Private() : defaultCharacterStyle(0), defaultParagraphStyle(0), \
defaultListStyle(0), defaultOutlineStyle(0), outlineStyle(0), undoStack(0), \
changeCommand(0), usingDefaultSet(false) {
}
~Private() {
@@ -92,6 +92,8 @@ public:
KUndo2Stack *undoStack;
ChangeStylesMacroCommand *changeCommand;
+ bool usingDefaultSet;
+
QVector<int> m_usedCharacterStyles;
QVector<int> m_usedParagraphStyles;
};
@@ -132,21 +134,7 @@ KoStyleManager::KoStyleManager(QObject *parent)
}
//default styles for ToCs
- int maxOutLineLevel = 10;
- for (int outlineLevel = 1; outlineLevel <= maxOutLineLevel; outlineLevel++) {
- KoParagraphStyle *style = new KoParagraphStyle();
- style->setName("Contents " + QString::number(outlineLevel));
- style->setLeftMargin(QTextLength(QTextLength::FixedLength, (outlineLevel - \
1) * 8));
- add(style);
- d->defaultToCEntriesStyleId.append(style->styleId());
- }
-
- for (int typeIndex = 0; typeIndex < \
KoOdfBibliographyConfiguration::bibTypes.size(); typeIndex++) {
- KoParagraphStyle *style = new KoParagraphStyle();
- style->setName("Bibliography " + \
KoOdfBibliographyConfiguration::bibTypes.at(typeIndex));
- add(style);
- d->defaultBibEntriesStyleId.append(style->styleId());
- }
+ createTOCStyles();
d->footNotesConfiguration = 0;
d->endNotesConfiguration = 0;
@@ -1169,4 +1157,77 @@ KoTextTableTemplate *KoStyleManager::tableTemplate(int id) \
const return d->tableTemplates.value(id, 0);
}
+void KoStyleManager::createDefaultSet()
+{
+ d->paragStyles.clear();
+ d->usingDefaultSet = true;
+
+ KoParagraphStyle *paragStyle = new KoParagraphStyle();
+ paragStyle->setName(i18n("Standard"));
+ paragStyle->setFontPointSize(12);
+ add(paragStyle);
+ d->defaultParagraphStyle = paragStyle;
+
+ paragStyle = new KoParagraphStyle();
+ paragStyle->setName(i18n("Document title"));
+ paragStyle->setFontPointSize(26);
+ paragStyle->setFontWeight(75);
+ paragStyle->setAlignment(Qt::AlignHCenter);
+ paragStyle->setNextStyle(d->defaultParagraphStyle->styleId());
+ add(paragStyle);
+
+ paragStyle = new KoParagraphStyle();
+ paragStyle->setName(i18n("Head 1"));
+ paragStyle->setFontPointSize(20);
+ paragStyle->setFontWeight(75);
+ paragStyle->setNextStyle(d->defaultParagraphStyle->styleId());
+ add(paragStyle);
+
+ paragStyle = new KoParagraphStyle();
+ paragStyle->setName(i18n("Head 2"));
+ paragStyle->setFontPointSize(16);
+ paragStyle->setFontWeight(75);
+ paragStyle->setNextStyle(d->defaultParagraphStyle->styleId());
+ add(paragStyle);
+}
+
+bool KoStyleManager::isUsingDefaultSet()
+{
+ return d->usingDefaultSet;
+}
+
+void KoStyleManager::useLoadedStyles()
+{
+ KoParagraphStyle *style;
+ foreach(style, d->paragStyles.values()) {
+ disconnect(style, SIGNAL(styleApplied(const KoParagraphStyle*)), this, \
SLOT(slotAppliedStyle(const KoParagraphStyle*))); + }
+
+ d->paragStyles.clear();
+ d->usingDefaultSet = false;
+
+ add(d->defaultParagraphStyle);
+
+ createTOCStyles();
+}
+
+void KoStyleManager::createTOCStyles()
+{
+ int maxOutLineLevel = 10;
+ for (int outlineLevel = 1; outlineLevel <= maxOutLineLevel; outlineLevel++) {
+ KoParagraphStyle *style = new KoParagraphStyle();
+ style->setName("Contents " + QString::number(outlineLevel));
+ style->setLeftMargin(QTextLength(QTextLength::FixedLength, (outlineLevel - \
1) * 8)); + add(style);
+ d->defaultToCEntriesStyleId.append(style->styleId());
+ }
+
+ for (int typeIndex = 0; typeIndex < \
KoOdfBibliographyConfiguration::bibTypes.size(); typeIndex++) { + \
KoParagraphStyle *style = new KoParagraphStyle(); + \
style->setName("Bibliography " + \
KoOdfBibliographyConfiguration::bibTypes.at(typeIndex)); + add(style);
+ d->defaultBibEntriesStyleId.append(style->styleId());
+ }
+}
+
#include <KoStyleManager.moc>
diff --git a/libs/kotext/styles/KoStyleManager.h \
b/libs/kotext/styles/KoStyleManager.h index c44ba32..c097080 100644
--- a/libs/kotext/styles/KoStyleManager.h
+++ b/libs/kotext/styles/KoStyleManager.h
@@ -456,6 +456,18 @@ public:
QVector<int> usedCharacterStyles() const;
QVector<int> usedParagraphStyles() const;
+ /** Creates a set of text styles to be used by applications which do not use \
full blown styling (loaded from an odt for example). + * For example Krita. These \
applications do not create a KoStyleManager by default. When they create a textshape, \
a KoStyleManager is created. + * The textshape factory will then call this method \
to generate a default set of styles. This will also set a flag (isUsingDefaultSet) \
which will be tested in the + * textshape ui in order not to hide the Standard \
style (default). + * TODO: maybe find a better system for all this.
+ */
+
+ void createDefaultSet();
+ bool isUsingDefaultSet();
+
+ void useLoadedStyles();
+
signals:
void styleAdded(KoParagraphStyle*);
void styleAdded(KoCharacterStyle*);
@@ -538,6 +550,8 @@ public slots:
void slotAppliedStyle(const KoParagraphStyle*);
private:
+ void createTOCStyles();
+
friend class ChangeFollower;
friend class ChangeStylesMacroCommand;
void remove(ChangeFollower *cf);
diff --git a/plugins/textshape/TextShapeFactory.cpp \
b/plugins/textshape/TextShapeFactory.cpp index d7e8fe8..56829cb 100644
--- a/plugins/textshape/TextShapeFactory.cpp
+++ b/plugins/textshape/TextShapeFactory.cpp
@@ -153,7 +153,9 @@ void \
TextShapeFactory::newDocumentResourceManager(KoDocumentResourceManager *man \
manager->setUndoStack(new KUndo2Stack(manager)); }
if (!manager->hasResource(KoText::StyleManager)) {
- variant.setValue(new KoStyleManager(manager));
+ KoStyleManager *styleManager = new KoStyleManager(manager);
+ styleManager->createDefaultSet();
+ variant.setValue(styleManager);
manager->setResource(KoText::StyleManager, variant);
}
if (!manager->imageCollection())
diff --git a/plugins/textshape/dialogs/DockerStylesComboModel.cpp \
b/plugins/textshape/dialogs/DockerStylesComboModel.cpp index a669b77..69efa70 100644
--- a/plugins/textshape/dialogs/DockerStylesComboModel.cpp
+++ b/plugins/textshape/dialogs/DockerStylesComboModel.cpp
@@ -119,7 +119,7 @@ void DockerStylesComboModel::setStyleManager(KoStyleManager *sm)
for ( ; begin != m_usedStyles.end(); ++begin) {
if (m_sourceModel->index(*begin, 0, QModelIndex()).internalId() \
!= -1) { //styleNone (internalId=-1) is a virtual style provided only for the UI. it \
does not exist in KoStyleManager
KoCharacterStyle *s = \
m_styleManager->characterStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId());
- if (KStringHandler::naturalCompare(compareStyle->name(), \
s->name()) < 0) { + if (!s || \
KStringHandler::naturalCompare(compareStyle->name(), s->name()) < 0) { break;
}
}
@@ -138,7 +138,7 @@ void DockerStylesComboModel::setStyleManager(KoStyleManager *sm)
for ( ; begin != m_usedStyles.end(); ++begin) {
if (m_sourceModel->index(*begin, 0, QModelIndex()).internalId() \
!= -1) { //styleNone (internalId=-1) is a virtual style provided only for the UI. it \
does not exist in KoStyleManager
KoParagraphStyle *s = \
m_styleManager->paragraphStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId());
- if (KStringHandler::naturalCompare(compareStyle->name(), \
s->name()) < 0) { + if (!s || \
KStringHandler::naturalCompare(compareStyle->name(), s->name()) < 0) { break;
}
}
@@ -153,6 +153,9 @@ void DockerStylesComboModel::setStyleManager(KoStyleManager *sm)
void DockerStylesComboModel::styleApplied(const KoCharacterStyle *style)
{
+ if (!style) {
+ return;
+ }
if (!m_usedStylesId.contains(style->styleId())) {
m_usedStylesId.append(style->styleId());
if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
@@ -160,7 +163,7 @@ void DockerStylesComboModel::styleApplied(const KoCharacterStyle \
*style) for ( ; begin != m_usedStyles.end(); ++begin) {
if (m_sourceModel->index(*begin, 0, QModelIndex()).internalId() != \
-1) { //styleNone (internalId=-1) is a virtual style provided only for the UI. it \
does not exist in KoStyleManager
KoCharacterStyle *s = \
m_styleManager->characterStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId());
- if (KStringHandler::naturalCompare(style->name(), s->name()) < \
0) { + if (!s || KStringHandler::naturalCompare(style->name(), \
s->name()) < 0) { break;
}
}
@@ -171,7 +174,7 @@ void DockerStylesComboModel::styleApplied(const KoCharacterStyle \
*style) QVector<int>::iterator begin = m_usedStyles.begin();
for ( ; begin != m_usedStyles.end(); ++begin) {
KoParagraphStyle *s = \
m_styleManager->paragraphStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId());
- if (KStringHandler::naturalCompare(style->name(), s->name()) < 0) {
+ if (!s || KStringHandler::naturalCompare(style->name(), s->name()) < \
0) { break;
}
}
@@ -215,7 +218,7 @@ void DockerStylesComboModel::createMapping()
QVector<int>::iterator begin = m_unusedStyles.begin();
for ( ; begin != m_unusedStyles.end(); ++begin) {
KoParagraphStyle *style = \
m_styleManager->paragraphStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId());
- if (KStringHandler::naturalCompare(paragStyle->name(), \
style->name()) < 0) { + if (!style || \
KStringHandler::naturalCompare(paragStyle->name(), style->name()) < 0) { break;
}
}
@@ -233,7 +236,7 @@ void DockerStylesComboModel::createMapping()
QVector<int>::iterator begin = m_unusedStyles.begin();
for ( ; begin != m_unusedStyles.end(); ++begin) {
KoCharacterStyle *style = \
m_styleManager->characterStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId());
- if (KStringHandler::naturalCompare(charStyle->name(), \
style->name()) < 0) { + if (!style || \
KStringHandler::naturalCompare(charStyle->name(), style->name()) < 0) { break;
}
}
diff --git a/plugins/textshape/dialogs/StylesModel.cpp \
b/plugins/textshape/dialogs/StylesModel.cpp index 2ac95fa..3926e34 100644
--- a/plugins/textshape/dialogs/StylesModel.cpp
+++ b/plugins/textshape/dialogs/StylesModel.cpp
@@ -353,7 +353,7 @@ void StylesModel::updateParagraphStyles()
qSort(styles.begin(), styles.end(), sortParagraphStyleByName);
foreach(KoParagraphStyle *style, styles) {
- if (style != m_styleManager->defaultParagraphStyle()) { //The default \
character style is not user selectable. It only provides individual property defaults \
and is not a style per say. + if (style != \
m_styleManager->defaultParagraphStyle() || m_styleManager->isUsingDefaultSet()) { \
//If we are not using the default set (for applications like Krita), the default \
paragraph style is not user selectable. It only provides individual property defaults \
and is not a style per say. m_styleList.append(style->styleId());
m_styleMapper->setMapping(style, style->styleId());
connect(style, SIGNAL(nameChanged(const QString&)), m_styleMapper, \
SLOT(map()));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic