Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Miguel Lopez
Krita
Commits
d610d750
Commit
d610d750
authored
Sep 12, 2019
by
Halla Rempt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the unused BibliographyGenerator
It leaks memory. CID:35382
parent
8a703c2c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
0 additions
and
293 deletions
+0
-293
plugins/flake/textshape/dialogs/BibliographyTemplate.cpp
plugins/flake/textshape/dialogs/BibliographyTemplate.cpp
+0
-26
plugins/flake/textshape/kotext/BibliographyGenerator.cpp
plugins/flake/textshape/kotext/BibliographyGenerator.cpp
+0
-216
plugins/flake/textshape/kotext/BibliographyGenerator.h
plugins/flake/textshape/kotext/BibliographyGenerator.h
+0
-47
plugins/flake/textshape/kotext/CMakeLists.txt
plugins/flake/textshape/kotext/CMakeLists.txt
+0
-1
plugins/flake/textshape/kotext/KoTextEditor.cpp
plugins/flake/textshape/kotext/KoTextEditor.cpp
+0
-3
No files found.
plugins/flake/textshape/dialogs/BibliographyTemplate.cpp
View file @
d610d750
...
...
@@ -39,32 +39,6 @@ QList<KoBibliographyInfo *> BibliographyTemplate::templates()
// when the bibliography is used the style will be automatically move to the usedStyle section
QList
<
KoBibliographyInfo
*>
predefinedTemplates
;
KoBibliographyInfo
*
firstTemplate
=
new
KoBibliographyInfo
();
firstTemplate
->
m_indexTitleTemplate
.
text
=
i18n
(
"Bibliography"
);
firstTemplate
->
m_indexTitleTemplate
.
styleId
=
m_manager
->
defaultBibliographyTitleStyle
()
->
styleId
();
firstTemplate
->
m_indexTitleTemplate
.
styleName
=
m_manager
->
defaultBibliographyTitleStyle
()
->
name
();
Q_FOREACH
(
const
QString
&
bibType
,
KoOdfBibliographyConfiguration
::
bibTypes
)
{
firstTemplate
->
m_entryTemplate
[
bibType
].
styleId
=
m_manager
->
defaultBibliographyEntryStyle
(
bibType
)
->
styleId
();
firstTemplate
->
m_entryTemplate
[
bibType
].
styleName
=
m_manager
->
defaultBibliographyEntryStyle
(
bibType
)
->
name
();
}
firstTemplate
->
m_entryTemplate
=
BibliographyGenerator
::
defaultBibliographyEntryTemplates
();
KoBibliographyInfo
*
secondTemplate
=
new
KoBibliographyInfo
();
secondTemplate
->
m_indexTitleTemplate
.
text
=
i18n
(
"References"
);
secondTemplate
->
m_indexTitleTemplate
.
styleId
=
m_manager
->
defaultBibliographyTitleStyle
()
->
styleId
();
secondTemplate
->
m_indexTitleTemplate
.
styleName
=
m_manager
->
defaultBibliographyTitleStyle
()
->
name
();
Q_FOREACH
(
const
QString
&
bibType
,
KoOdfBibliographyConfiguration
::
bibTypes
)
{
secondTemplate
->
m_entryTemplate
[
bibType
].
styleId
=
m_manager
->
defaultBibliographyEntryStyle
(
bibType
)
->
styleId
();
secondTemplate
->
m_entryTemplate
[
bibType
].
styleName
=
m_manager
->
defaultBibliographyEntryStyle
(
bibType
)
->
name
();
}
secondTemplate
->
m_entryTemplate
=
BibliographyGenerator
::
defaultBibliographyEntryTemplates
();
predefinedTemplates
.
append
(
firstTemplate
);
predefinedTemplates
.
append
(
secondTemplate
);
return
predefinedTemplates
;
}
...
...
plugins/flake/textshape/kotext/BibliographyGenerator.cpp
deleted
100644 → 0
View file @
8a703c2c
/* This file is part of the KDE project
* Copyright (C) 2011 Smit Patel <smitpatel24@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "BibliographyGenerator.h"
#include "KoInlineCite.h"
#include <klocalizedstring.h>
#include <KoOdfBibliographyConfiguration.h>
#include <KoInlineTextObjectManager.h>
#include <KoParagraphStyle.h>
#include <KoTextDocument.h>
#include <KoStyleManager.h>
#include <QTextFrame>
static
QList
<
SortKeyPair
>
sortKeys
;
BibliographyGenerator
::
BibliographyGenerator
(
QTextDocument
*
bibDocument
,
const
QTextBlock
&
block
,
KoBibliographyInfo
*
bibInfo
)
:
QObject
(
bibDocument
)
,
m_bibDocument
(
bibDocument
)
,
m_bibInfo
(
bibInfo
)
,
m_block
(
block
)
{
Q_ASSERT
(
bibDocument
);
Q_ASSERT
(
bibInfo
);
m_bibInfo
->
setGenerator
(
this
);
bibDocument
->
setUndoRedoEnabled
(
false
);
generate
();
}
BibliographyGenerator
::~
BibliographyGenerator
()
{
delete
m_bibInfo
;
}
static
bool
compare_on
(
int
keyIndex
,
KoInlineCite
*
c1
,
KoInlineCite
*
c2
)
{
if
(
keyIndex
==
sortKeys
.
size
()
)
return
false
;
else
if
(
sortKeys
[
keyIndex
].
second
==
Qt
::
AscendingOrder
)
{
if
(
c1
->
dataField
(
sortKeys
[
keyIndex
].
first
)
<
c2
->
dataField
(
sortKeys
[
keyIndex
].
first
))
return
true
;
else
if
(
c1
->
dataField
(
sortKeys
[
keyIndex
].
first
)
>
c2
->
dataField
(
sortKeys
[
keyIndex
].
first
))
return
false
;
}
else
if
(
sortKeys
[
keyIndex
].
second
==
Qt
::
DescendingOrder
)
{
if
(
c1
->
dataField
(
sortKeys
[
keyIndex
].
first
)
<
c2
->
dataField
(
sortKeys
[
keyIndex
].
first
))
return
false
;
else
if
(
c1
->
dataField
(
sortKeys
[
keyIndex
].
first
)
>
c2
->
dataField
(
sortKeys
[
keyIndex
].
first
))
return
true
;
}
else
return
compare_on
(
keyIndex
+
1
,
c1
,
c2
);
return
false
;
}
static
bool
lessThan
(
KoInlineCite
*
c1
,
KoInlineCite
*
c2
)
{
return
compare_on
(
0
,
c1
,
c2
);
}
static
QList
<
KoInlineCite
*>
sort
(
QList
<
KoInlineCite
*>
cites
,
QList
<
SortKeyPair
>
keys
)
{
sortKeys
=
keys
;
sortKeys
<<
QPair
<
QString
,
Qt
::
SortOrder
>
(
"identifier"
,
Qt
::
AscendingOrder
);
std
::
sort
(
cites
.
begin
(),
cites
.
end
(),
lessThan
);
return
cites
;
}
void
BibliographyGenerator
::
generate
()
{
if
(
!
m_bibInfo
)
return
;
QTextCursor
cursor
=
m_bibDocument
->
rootFrame
()
->
lastCursorPosition
();
cursor
.
setPosition
(
m_bibDocument
->
rootFrame
()
->
firstPosition
(),
QTextCursor
::
KeepAnchor
);
cursor
.
beginEditBlock
();
KoTextDocument
koDocument
(
m_block
.
document
());
KoStyleManager
*
styleManager
=
koDocument
.
styleManager
();
if
(
!
m_bibInfo
->
m_indexTitleTemplate
.
text
.
isNull
())
{
KoParagraphStyle
*
titleStyle
=
styleManager
->
paragraphStyle
(
m_bibInfo
->
m_indexTitleTemplate
.
styleId
);
if
(
!
titleStyle
)
{
titleStyle
=
styleManager
->
defaultBibliographyTitleStyle
();
m_bibInfo
->
m_indexTitleTemplate
.
styleName
=
titleStyle
->
name
();
}
QTextBlock
titleTextBlock
=
cursor
.
block
();
titleStyle
->
applyStyle
(
titleTextBlock
);
cursor
.
insertText
(
m_bibInfo
->
m_indexTitleTemplate
.
text
);
cursor
.
insertBlock
();
}
QTextCharFormat
savedCharFormat
=
cursor
.
charFormat
();
QList
<
KoInlineCite
*>
citeList
;
if
(
styleManager
->
bibliographyConfiguration
()
->
sortByPosition
())
{
citeList
=
koDocument
.
inlineTextObjectManager
()
->
citationsSortedByPosition
(
false
,
m_block
.
document
()
->
firstBlock
());
}
else
{
citeList
=
sort
(
koDocument
.
inlineTextObjectManager
()
->
citationsSortedByPosition
(
false
,
m_block
.
document
()
->
firstBlock
()),
koDocument
.
styleManager
()
->
bibliographyConfiguration
()
->
sortKeys
());
}
foreach
(
KoInlineCite
*
cite
,
citeList
)
{
KoParagraphStyle
*
bibTemplateStyle
=
0
;
BibliographyEntryTemplate
bibEntryTemplate
;
if
(
m_bibInfo
->
m_entryTemplate
.
contains
(
cite
->
bibliographyType
()))
{
bibEntryTemplate
=
m_bibInfo
->
m_entryTemplate
[
cite
->
bibliographyType
()];
bibTemplateStyle
=
styleManager
->
paragraphStyle
(
bibEntryTemplate
.
styleId
);
if
(
bibTemplateStyle
==
0
)
{
bibTemplateStyle
=
styleManager
->
defaultBibliographyEntryStyle
(
bibEntryTemplate
.
bibliographyType
);
bibEntryTemplate
.
styleName
=
bibTemplateStyle
->
name
();
}
}
else
{
continue
;
}
cursor
.
insertBlock
(
QTextBlockFormat
(),
QTextCharFormat
());
QTextBlock
bibEntryTextBlock
=
cursor
.
block
();
bibTemplateStyle
->
applyStyle
(
bibEntryTextBlock
);
bool
spanEnabled
=
false
;
//true if data field is not empty
foreach
(
IndexEntry
*
entry
,
bibEntryTemplate
.
indexEntries
)
{
switch
(
entry
->
name
)
{
case
IndexEntry
::
BIBLIOGRAPHY
:
{
IndexEntryBibliography
*
indexEntry
=
static_cast
<
IndexEntryBibliography
*>
(
entry
);
cursor
.
insertText
(
QString
(((
spanEnabled
)
?
" "
:
""
)).
append
(
cite
->
dataField
(
indexEntry
->
dataField
)));
spanEnabled
=
!
cite
->
dataField
(
indexEntry
->
dataField
).
isEmpty
();
break
;
}
case
IndexEntry
::
SPAN
:
{
if
(
spanEnabled
)
{
IndexEntrySpan
*
span
=
static_cast
<
IndexEntrySpan
*>
(
entry
);
cursor
.
insertText
(
span
->
text
);
}
break
;
}
case
IndexEntry
::
TAB_STOP
:
{
IndexEntryTabStop
*
tabEntry
=
static_cast
<
IndexEntryTabStop
*>
(
entry
);
cursor
.
insertText
(
"
\t
"
);
QTextBlockFormat
blockFormat
=
cursor
.
blockFormat
();
QList
<
QVariant
>
tabList
;
if
(
tabEntry
->
m_position
==
"MAX"
)
{
tabEntry
->
tab
.
position
=
m_maxTabPosition
;
}
else
{
tabEntry
->
tab
.
position
=
tabEntry
->
m_position
.
toDouble
();
}
tabList
.
append
(
QVariant
::
fromValue
<
KoText
::
Tab
>
(
tabEntry
->
tab
));
blockFormat
.
setProperty
(
KoParagraphStyle
::
TabPositions
,
QVariant
::
fromValue
<
QList
<
QVariant
>
>
(
tabList
));
cursor
.
setBlockFormat
(
blockFormat
);
break
;
}
default:
{
break
;
}
}
}
// foreach
}
cursor
.
setCharFormat
(
savedCharFormat
);
// restore the cursor char format
}
QMap
<
QString
,
BibliographyEntryTemplate
>
BibliographyGenerator
::
defaultBibliographyEntryTemplates
()
{
QMap
<
QString
,
BibliographyEntryTemplate
>
entryTemplates
;
foreach
(
const
QString
&
bibType
,
KoOdfBibliographyConfiguration
::
bibTypes
)
{
BibliographyEntryTemplate
bibEntryTemplate
;
//Now creating default IndexEntries for all BibliographyEntryTemplates
IndexEntryBibliography
*
identifier
=
new
IndexEntryBibliography
(
QString
());
IndexEntryBibliography
*
author
=
new
IndexEntryBibliography
(
QString
());
IndexEntryBibliography
*
title
=
new
IndexEntryBibliography
(
QString
());
IndexEntryBibliography
*
year
=
new
IndexEntryBibliography
(
QString
());
IndexEntrySpan
*
firstSpan
=
new
IndexEntrySpan
(
QString
());
IndexEntrySpan
*
otherSpan
=
new
IndexEntrySpan
(
QString
());
identifier
->
dataField
=
"identifier"
;
author
->
dataField
=
"author"
;
title
->
dataField
=
"title"
;
year
->
dataField
=
"year"
;
firstSpan
->
text
=
":"
;
otherSpan
->
text
=
","
;
bibEntryTemplate
.
bibliographyType
=
bibType
;
bibEntryTemplate
.
indexEntries
.
append
(
static_cast
<
IndexEntry
*>
(
identifier
));
bibEntryTemplate
.
indexEntries
.
append
(
static_cast
<
IndexEntry
*>
(
firstSpan
));
bibEntryTemplate
.
indexEntries
.
append
(
static_cast
<
IndexEntry
*>
(
author
));
bibEntryTemplate
.
indexEntries
.
append
(
static_cast
<
IndexEntry
*>
(
otherSpan
));
bibEntryTemplate
.
indexEntries
.
append
(
static_cast
<
IndexEntry
*>
(
title
));
bibEntryTemplate
.
indexEntries
.
append
(
static_cast
<
IndexEntry
*>
(
otherSpan
));
bibEntryTemplate
.
indexEntries
.
append
(
static_cast
<
IndexEntry
*>
(
year
));
entryTemplates
[
bibType
]
=
bibEntryTemplate
;
}
return
entryTemplates
;
}
plugins/flake/textshape/kotext/BibliographyGenerator.h
deleted
100644 → 0
View file @
8a703c2c
/* This file is part of the KDE project
* Copyright (C) 2011 Smit Patel <smitpatel24@gmail.com>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef BIBLIOGRAPHYGENERATOR_H
#define BIBLIOGRAPHYGENERATOR_H
#include <KoBibliographyInfo.h>
#include "kritatext_export.h"
#include <QTextBlock>
class
KRITATEXT_EXPORT
BibliographyGenerator
:
public
QObject
,
public
BibliographyGeneratorInterface
{
Q_OBJECT
public:
explicit
BibliographyGenerator
(
QTextDocument
*
bibDocument
,
const
QTextBlock
&
block
,
KoBibliographyInfo
*
bibInfo
);
~
BibliographyGenerator
()
override
;
static
QMap
<
QString
,
BibliographyEntryTemplate
>
defaultBibliographyEntryTemplates
();
public
Q_SLOTS
:
void
generate
();
private:
QTextDocument
*
m_document
;
QTextDocument
*
m_bibDocument
;
KoBibliographyInfo
*
m_bibInfo
;
QTextBlock
m_block
;
qreal
m_maxTabPosition
;
};
#endif
plugins/flake/textshape/kotext/CMakeLists.txt
View file @
d610d750
...
...
@@ -61,7 +61,6 @@ set(kritatext_LIB_SRCS
ToCBibGeneratorInfo.cpp
KoTableOfContentsGeneratorInfo.cpp
KoBibliographyInfo.cpp
BibliographyGenerator.cpp
styles/Styles_p.cpp
styles/KoCharacterStyle.cpp
...
...
plugins/flake/textshape/kotext/KoTextEditor.cpp
View file @
d610d750
...
...
@@ -32,7 +32,6 @@
#include "KoInlineTextObjectManager.h"
#include "KoInlineNote.h"
#include "KoInlineCite.h"
#include "BibliographyGenerator.h"
#include <KoTextShapeDataBase.h>
#include <KoSelection.h>
#include <KoShapeController.h>
...
...
@@ -1203,8 +1202,6 @@ void KoTextEditor::insertBibliography(KoBibliographyInfo *info)
d
->
caret
.
insertBlock
(
bibFormat
);
d
->
caret
.
movePosition
(
QTextCursor
::
Right
);
new
BibliographyGenerator
(
bibDocument
,
block
(),
newBibInfo
);
if
(
hasSelection
)
{
d
->
caret
.
endEditBlock
();
endEditBlock
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment