[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra/textshape-stylesWidget-PierreSt] /: Fix crash in Krita on the new styles combo
From: Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date: 2013-02-03 21:41:38
Message-ID: 20130203214138.97516A60DA () git ! kde ! org
[Download RAW message or body]
Git commit 980f34c7b2ed24496b15984d16720561448c0e13 by Pierre Stirnweiss.
Committed on 21/01/2013 at 20:19.
Pushed by pstirnweiss into branch 'textshape-stylesWidget-PierreSt'.
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 +42 -1 libs/kotext/styles/KoStyleManager.cpp
M +10 -0 libs/kotext/styles/KoStyleManager.h
M +3 -1 plugins/textshape/TextShapeFactory.cpp
M +7 -4 plugins/textshape/dialogs/DockerStylesComboModel.cpp
M +1 -1 plugins/textshape/dialogs/StylesModel.cpp
http://commits.kde.org/calligra/980f34c7b2ed24496b15984d16720561448c0e13
diff --git a/libs/kotext/styles/KoStyleManager.cpp \
b/libs/kotext/styles/KoStyleManager.cpp index c2a64e9..935f83e 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;
};
@@ -1169,4 +1171,43 @@ 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;
+}
+
#include <KoStyleManager.moc>
diff --git a/libs/kotext/styles/KoStyleManager.h \
b/libs/kotext/styles/KoStyleManager.h index c44ba32..0fe92d6 100644
--- a/libs/kotext/styles/KoStyleManager.h
+++ b/libs/kotext/styles/KoStyleManager.h
@@ -456,6 +456,16 @@ 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();
+
signals:
void styleAdded(KoParagraphStyle*);
void styleAdded(KoCharacterStyle*);
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..227ec00 100644
--- a/plugins/textshape/dialogs/DockerStylesComboModel.cpp
+++ b/plugins/textshape/dialogs/DockerStylesComboModel.cpp
@@ -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