Changeset View
Changeset View
Standalone View
Standalone View
plugins/textshape/dialogs/SimpleCitationBibliographyWidget.cpp
Show All 22 Lines | |||||
23 | #include "BibliographyTemplate.h" | 23 | #include "BibliographyTemplate.h" | ||
24 | #include <KoBibliographyInfo.h> | 24 | #include <KoBibliographyInfo.h> | ||
25 | #include <KoTextEditor.h> | 25 | #include <KoTextEditor.h> | ||
26 | 26 | | |||
27 | #include <QAction> | 27 | #include <QAction> | ||
28 | #include <QDebug> | 28 | #include <QDebug> | ||
29 | 29 | | |||
30 | #include <QWidget> | 30 | #include <QWidget> | ||
31 | #include <QSignalMapper> | | |||
32 | 31 | | |||
33 | SimpleCitationBibliographyWidget::SimpleCitationBibliographyWidget(ReferencesTool *tool, QWidget *parent) | 32 | SimpleCitationBibliographyWidget::SimpleCitationBibliographyWidget(ReferencesTool *tool, QWidget *parent) | ||
34 | : QWidget(parent), | 33 | : QWidget(parent), | ||
35 | m_blockSignals(false), | 34 | m_blockSignals(false), | ||
36 | m_referenceTool(tool), | 35 | m_referenceTool(tool) | ||
37 | m_signalMapper(0) | | |||
38 | { | 36 | { | ||
39 | widget.setupUi(this); | 37 | widget.setupUi(this); | ||
40 | Q_ASSERT(tool); | 38 | Q_ASSERT(tool); | ||
41 | 39 | | |||
42 | m_templateGenerator = new BibliographyTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | 40 | m_templateGenerator = new BibliographyTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | ||
43 | 41 | | |||
44 | widget.addCitation->setDefaultAction(tool->action("insert_citation")); | 42 | widget.addCitation->setDefaultAction(tool->action("insert_citation")); | ||
45 | connect(widget.addCitation,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus())); | 43 | connect(widget.addCitation,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus())); | ||
Show All 15 Lines | |||||
61 | void SimpleCitationBibliographyWidget::setStyleManager(KoStyleManager *sm) | 59 | void SimpleCitationBibliographyWidget::setStyleManager(KoStyleManager *sm) | ||
62 | { | 60 | { | ||
63 | m_styleManager = sm; | 61 | m_styleManager = sm; | ||
64 | } | 62 | } | ||
65 | 63 | | |||
66 | void SimpleCitationBibliographyWidget::prepareTemplateMenu() | 64 | void SimpleCitationBibliographyWidget::prepareTemplateMenu() | ||
67 | { | 65 | { | ||
68 | m_previewGenerator.clear(); | 66 | m_previewGenerator.clear(); | ||
69 | if (m_signalMapper) { | | |||
70 | delete m_signalMapper; | | |||
71 | m_signalMapper = 0; | | |||
72 | } | | |||
73 | qDeleteAll(m_templateList.begin(), m_templateList.end()); | 67 | qDeleteAll(m_templateList.begin(), m_templateList.end()); | ||
74 | m_templateList.clear(); | 68 | m_templateList.clear(); | ||
75 | 69 | | |||
76 | m_signalMapper = new QSignalMapper(); | | |||
77 | | ||||
78 | m_templateList = m_templateGenerator->templates(); | 70 | m_templateList = m_templateGenerator->templates(); | ||
79 | 71 | | |||
80 | connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(pixmapReady(int))); | | |||
81 | | ||||
82 | m_chooser = widget.addBibliography->addItemChooser(1); | 72 | m_chooser = widget.addBibliography->addItemChooser(1); | ||
83 | 73 | | |||
84 | int index = 0; | 74 | int index = 0; | ||
85 | foreach (KoBibliographyInfo *info, m_templateList) { | 75 | foreach (KoBibliographyInfo *info, m_templateList) { | ||
86 | BibliographyPreview *preview = new BibliographyPreview(); | 76 | BibliographyPreview *preview = new BibliographyPreview(); | ||
87 | preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | 77 | preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); | ||
88 | preview->setPreviewSize(QSize(200,120)); | 78 | preview->setPreviewSize(QSize(200,120)); | ||
89 | preview->updatePreview(info); | 79 | preview->updatePreview(info); | ||
90 | connect(preview, SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); | 80 | connect(preview, &BibliographyPreview::pixmapGenerated, [this, index] { pixmapReady(index); }); | ||
dfaure: you know what I'm going to say ;)
+ add `this` as 3rd argument | |||||
91 | m_signalMapper->setMapping(preview, index); | | |||
92 | m_previewGenerator.append(preview); | 81 | m_previewGenerator.append(preview); | ||
93 | ++index; | 82 | ++index; | ||
94 | 83 | | |||
95 | //put dummy pixmaps until the actual pixmap previews are generated and added in pixmapReady() | 84 | //put dummy pixmaps until the actual pixmap previews are generated and added in pixmapReady() | ||
96 | if (! widget.addBibliography->hasItemId(index)) { | 85 | if (! widget.addBibliography->hasItemId(index)) { | ||
97 | QPixmap pmm(QSize(200,120)); | 86 | QPixmap pmm(QSize(200,120)); | ||
98 | pmm.fill(Qt::white); | 87 | pmm.fill(Qt::white); | ||
99 | widget.addBibliography->addItem(m_chooser, pmm, index); | 88 | widget.addBibliography->addItem(m_chooser, pmm, index); | ||
Show All 13 Lines | 100 | { | |||
113 | m_referenceTool->insertCustomBibliography(m_templateList.at(0)); | 102 | m_referenceTool->insertCustomBibliography(m_templateList.at(0)); | ||
114 | } | 103 | } | ||
115 | 104 | | |||
116 | 105 | | |||
117 | void SimpleCitationBibliographyWidget::pixmapReady(int templateId) | 106 | void SimpleCitationBibliographyWidget::pixmapReady(int templateId) | ||
118 | { | 107 | { | ||
119 | // +1 to the templateId is because formattingButton does not allow id = 0 | 108 | // +1 to the templateId is because formattingButton does not allow id = 0 | ||
120 | widget.addBibliography->addItem(m_chooser, m_previewGenerator.at(templateId)->previewPixmap(), templateId + 1); | 109 | widget.addBibliography->addItem(m_chooser, m_previewGenerator.at(templateId)->previewPixmap(), templateId + 1); | ||
121 | disconnect(m_previewGenerator.at(templateId), SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map())); | 110 | disconnect(m_previewGenerator.at(templateId), &BibliographyPreview::pixmapGenerated, this, nullptr); | ||
This is a bit dangerous, it also disconnects any other possible receiver. You should be able to pass this as 3rd arg instead of nullptr, if you pass this at connect time too. (this applies to all the disconnects in this change request) dfaure: This is a bit dangerous, it also disconnects any other possible receiver. You should be able to… | |||||
122 | m_previewGenerator.at(templateId)->deleteLater(); | 111 | m_previewGenerator.at(templateId)->deleteLater(); | ||
123 | } | 112 | } | ||
124 | 113 | | |||
125 | void SimpleCitationBibliographyWidget::applyTemplate(int templateId) | 114 | void SimpleCitationBibliographyWidget::applyTemplate(int templateId) | ||
126 | { | 115 | { | ||
127 | m_templateGenerator->moveTemplateToUsed(m_templateList.at(templateId - 1)); | 116 | m_templateGenerator->moveTemplateToUsed(m_templateList.at(templateId - 1)); | ||
128 | m_referenceTool->editor()->insertBibliography(m_templateList.at(templateId - 1)); | 117 | m_referenceTool->editor()->insertBibliography(m_templateList.at(templateId - 1)); | ||
129 | } | 118 | } |
you know what I'm going to say ;)
+ add this as 3rd argument