[pim/kcalutils] /: Remove the ability to construct a DndFactory instance
Volker Krause <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit a8ca2d78a5ca855ae9d6f8f925941ed729971c5c by Volker Krause.
Committed on 16/07/2026 at 16:04.
Pushed by vkrause into branch 'master'.
Remove the ability to construct a DndFactory instance
It only has static methods meanwhile.
M +6 -18 autotests/testdndfactory.cpp
M +53 -67 src/dndfactory.cpp
M +0 -20 src/dndfactory.h
https://invent.kde.org/pim/kcalutils/-/commit/a8ca2d78a5ca855ae9d6f8f925941ed729971c5c
diff --git a/autotests/testdndfactory.cpp b/autotests/testdndfactory.cpp
index f445334eb..c0b7b0b46 100644
--- a/autotests/testdndfactory.cpp
+++ b/autotests/testdndfactory.cpp
@@ -23,10 +23,6 @@ using namespace KCalUtils;
void DndFactoryTest::testPasteAllDayEvent()
{
- const MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::systemTimeZone()));
-
- DndFactory factory(calendar);
-
const Event::Ptr allDayEvent(new Event());
allDayEvent->setSummary(QStringLiteral("Summary 1"));
allDayEvent->setDtStart(QDateTime(QDate(2010, 8, 8), {}));
@@ -38,9 +34,9 @@ void DndFactoryTest::testPasteAllDayEvent()
Incidence::List incidencesToPaste;
incidencesToPaste.append(allDayEvent);
- QVERIFY(factory.copyIncidences(incidencesToPaste));
+ QVERIFY(DndFactory::copyIncidences(incidencesToPaste));
- Incidence::List pastedIncidences = factory.pasteIncidences();
+ Incidence::List pastedIncidences = DndFactory::pasteIncidences();
QVERIFY(pastedIncidences.size() == 1);
const Incidence::Ptr &incidence = pastedIncidences.first();
@@ -62,10 +58,6 @@ void DndFactoryTest::testPasteAllDayEvent()
void DndFactoryTest::testPasteAllDayEvent2()
{
- const MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::systemTimeZone()));
-
- DndFactory factory(calendar);
-
const Event::Ptr allDayEvent(new Event());
allDayEvent->setSummary(QStringLiteral("Summary 2"));
allDayEvent->setDtStart(QDateTime(QDate(2010, 8, 8), {}));
@@ -76,12 +68,12 @@ void DndFactoryTest::testPasteAllDayEvent2()
Incidence::List incidencesToPaste;
incidencesToPaste.append(allDayEvent);
- QVERIFY(factory.copyIncidences(incidencesToPaste));
+ QVERIFY(DndFactory::copyIncidences(incidencesToPaste));
const QDateTime newDateTime(QDate(2011, 1, 1).startOfDay());
const uint originalLength = allDayEvent->dtStart().secsTo(allDayEvent->dtEnd());
// paste at the new time
- Incidence::List pastedIncidences = factory.pasteIncidences(newDateTime);
+ Incidence::List pastedIncidences = DndFactory::pasteIncidences(newDateTime);
// we only copied one incidence
QVERIFY(pastedIncidences.size() == 1);
@@ -112,10 +104,6 @@ void DndFactoryTest::testPasteAllDayEvent2()
void DndFactoryTest::testPasteTodo()
{
- const MemoryCalendar::Ptr calendar(new MemoryCalendar(QTimeZone::systemTimeZone()));
-
- DndFactory factory(calendar);
-
const Todo::Ptr todo(new Todo());
todo->setSummary(QStringLiteral("Summary 1"));
todo->setDtDue(QDateTime(QDate(2010, 8, 9), {}));
@@ -123,11 +111,11 @@ void DndFactoryTest::testPasteTodo()
Incidence::List incidencesToPaste;
incidencesToPaste.append(todo);
- QVERIFY(factory.copyIncidences(incidencesToPaste));
+ QVERIFY(DndFactory::copyIncidences(incidencesToPaste));
const QDateTime newDateTime(QDate(2011, 1, 1), QTime(10, 10));
- Incidence::List pastedIncidences = factory.pasteIncidences(newDateTime);
+ Incidence::List pastedIncidences = DndFactory::pasteIncidences(newDateTime);
QVERIFY(pastedIncidences.size() == 1);
const Incidence::Ptr &incidence = pastedIncidences.first();
diff --git a/src/dndfactory.cpp b/src/dndfactory.cpp
index af5d727e8..9c8bc01c9 100644
--- a/src/dndfactory.cpp
+++ b/src/dndfactory.cpp
@@ -52,81 +52,67 @@ static QDateTime copyTimeSpec(const QDateTime &dt, const QDateTime &source)
Q_UNREACHABLE();
}
-/**
- DndFactoryPrivate class that helps to provide binary compatibility between releases.
- @internal
-*/
//@cond PRIVATE
-class KCalUtils::DndFactoryPrivate
+static Incidence::Ptr pasteIncidence(const Incidence::Ptr &incidence, QDateTime newDateTime, DndFactory::PasteFlags pasteOptions)
{
-public:
- static Incidence::Ptr pasteIncidence(const Incidence::Ptr &incidence, QDateTime newDateTime, DndFactory::PasteFlags pasteOptions)
- {
- Incidence::Ptr inc(incidence);
-
- if (inc) {
- inc = Incidence::Ptr(inc->clone());
- inc->recreate();
- }
+ Incidence::Ptr inc(incidence);
+
+ if (inc) {
+ inc = Incidence::Ptr(inc->clone());
+ inc->recreate();
+ }
- if (inc && newDateTime.isValid()) {
- if (inc->type() == Incidence::TypeEvent) {
- Event::Ptr const event = inc.staticCast<Event>();
- if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
- // Set date and preserve time and timezone stuff
- const QDate date = newDateTime.date();
- newDateTime = event->dtStart();
- newDateTime.setDate(date);
- }
-
- // in seconds
- const qint64 durationInSeconds = event->dtStart().secsTo(event->dtEnd());
- const qint64 durationInDays = event->dtStart().daysTo(event->dtEnd());
-
- if (incidence->allDay()) {
- event->setDtStart(QDateTime(newDateTime.date(), {}));
- event->setDtEnd(newDateTime.addDays(durationInDays));
- } else {
- event->setDtStart(copyTimeSpec(newDateTime, event->dtStart()));
- event->setDtEnd(copyTimeSpec(newDateTime.addSecs(durationInSeconds), event->dtEnd()));
- }
- } else if (inc->type() == Incidence::TypeTodo) {
- Todo::Ptr const aTodo = inc.staticCast<Todo>();
- const bool pasteAtDtStart = (pasteOptions & DndFactory::FlagTodosPasteAtDtStart);
- if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
- // Set date and preserve time and timezone stuff
- const QDate date = newDateTime.date();
- newDateTime = pasteAtDtStart ? aTodo->dtStart() : aTodo->dtDue();
- newDateTime.setDate(date);
- }
- if (pasteAtDtStart) {
- aTodo->setDtStart(copyTimeSpec(newDateTime, aTodo->dtStart()));
- } else {
- aTodo->setDtDue(copyTimeSpec(newDateTime, aTodo->dtDue()));
- }
- } else if (inc->type() == Incidence::TypeJournal) {
- if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
- // Set date and preserve time and timezone stuff
- const QDate date = newDateTime.date();
- newDateTime = inc->dtStart();
- newDateTime.setDate(date);
- }
- inc->setDtStart(copyTimeSpec(newDateTime, inc->dtStart()));
+ if (inc && newDateTime.isValid()) {
+ if (inc->type() == Incidence::TypeEvent) {
+ Event::Ptr const event = inc.staticCast<Event>();
+ if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
+ // Set date and preserve time and timezone stuff
+ const QDate date = newDateTime.date();
+ newDateTime = event->dtStart();
+ newDateTime.setDate(date);
+ }
+
+ // in seconds
+ const qint64 durationInSeconds = event->dtStart().secsTo(event->dtEnd());
+ const qint64 durationInDays = event->dtStart().daysTo(event->dtEnd());
+
+ if (incidence->allDay()) {
+ event->setDtStart(QDateTime(newDateTime.date(), {}));
+ event->setDtEnd(newDateTime.addDays(durationInDays));
+ } else {
+ event->setDtStart(copyTimeSpec(newDateTime, event->dtStart()));
+ event->setDtEnd(copyTimeSpec(newDateTime.addSecs(durationInSeconds), event->dtEnd()));
+ }
+ } else if (inc->type() == Incidence::TypeTodo) {
+ Todo::Ptr const aTodo = inc.staticCast<Todo>();
+ const bool pasteAtDtStart = (pasteOptions & DndFactory::FlagTodosPasteAtDtStart);
+ if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
+ // Set date and preserve time and timezone stuff
+ const QDate date = newDateTime.date();
+ newDateTime = pasteAtDtStart ? aTodo->dtStart() : aTodo->dtDue();
+ newDateTime.setDate(date);
+ }
+ if (pasteAtDtStart) {
+ aTodo->setDtStart(copyTimeSpec(newDateTime, aTodo->dtStart()));
} else {
- qCDebug(KCALUTILS_LOG) << "Trying to paste unknown incidence of type" << int(inc->type());
+ aTodo->setDtDue(copyTimeSpec(newDateTime, aTodo->dtDue()));
+ }
+ } else if (inc->type() == Incidence::TypeJournal) {
+ if (pasteOptions & DndFactory::FlagPasteAtOriginalTime) {
+ // Set date and preserve time and timezone stuff
+ const QDate date = newDateTime.date();
+ newDateTime = inc->dtStart();
+ newDateTime.setDate(date);
}
+ inc->setDtStart(copyTimeSpec(newDateTime, inc->dtStart()));
+ } else {
+ qCDebug(KCALUTILS_LOG) << "Trying to paste unknown incidence of type" << int(inc->type());
}
-
- return inc;
}
-};
-//@endcond
-DndFactory::DndFactory([[maybe_unused]] const Calendar::Ptr &calendar)
-{
+ return inc;
}
-
-DndFactory::~DndFactory() = default;
+//@endcond
Calendar::Ptr DndFactory::createDropCalendar(const QMimeData *mimeData)
{
@@ -218,7 +204,7 @@ Incidence::List DndFactory::pasteIncidences(const QDateTime &newDateTime, PasteF
const Incidence::List incidences = calendar->incidences();
Incidence::List::ConstIterator end(incidences.constEnd());
for (it = incidences.constBegin(); it != end; ++it) {
- Incidence::Ptr const incidence = DndFactoryPrivate::pasteIncidence(*it, newDateTime, pasteOptions);
+ Incidence::Ptr const incidence = pasteIncidence(*it, newDateTime, pasteOptions);
if (incidence) {
list.append(incidence);
oldUidToNewInc[(*it)->uid()] = *it;
diff --git a/src/dndfactory.h b/src/dndfactory.h
index 266887cd7..873fd9df0 100644
--- a/src/dndfactory.h
+++ b/src/dndfactory.h
@@ -27,13 +27,10 @@
#include <QDateTime>
-#include <memory>
-
class QMimeData;
namespace KCalUtils
{
-class DndFactoryPrivate;
/*!
\class KCalUtils::DndFactory
\inmodule KCalUtils
@@ -58,19 +55,6 @@ public:
Q_DECLARE_FLAGS(PasteFlags, PasteFlag)
- /*!
- Constructor of the DndFactory class.
- \param cal the calendar associated with the factory
- */
- [[deprecated("no need to instantiate DndFactory anymore, only static methods left")]]
- explicit DndFactory(const KCalendarCore::Calendar::Ptr &cal);
-
- /*!
- Destructor of the DndFactory class.
- */
- [[deprecated("no need to instantiate DndFactory anymore, only static methods left")]]
- ~DndFactory();
-
/*!
Create the calendar that is contained in the mime data.
*/
@@ -106,9 +90,5 @@ public:
Returns the cloned incidence.
*/
static KCalendarCore::Incidence::List pasteIncidences(const QDateTime &newDateTime = QDateTime(), PasteFlags pasteOptions = PasteFlags());
-
-private:
- Q_DISABLE_COPY(DndFactory)
- std::unique_ptr<DndFactoryPrivate> const d;
};
}