Commit 8b7e60c7 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to KDiagram

parent 823fa746
......@@ -4,12 +4,19 @@ include_directories(
../
)
if (KDIAGRAM_SUPPORT)
set(grant_lib KGantt)
else()
set(grant_lib KF5::KDGantt2)
endif()
MACRO(IE_UNIT_TESTS)
FOREACH(_testname ${ARGN})
add_executable( ${_testname} ${_testname}.cpp modeltest.cpp )
add_test( ${_testname} ${_testname} )
ecm_mark_as_test(${_testname})
target_link_libraries(${_testname} Qt5::Test KF5::AkonadiCore KF5::KDGantt2 KF5::CalendarUtils KF5::CalendarCore KF5::IncidenceEditor KF5::KdepimDBusInterfaces KF5::Libkdepim)
target_link_libraries(${_testname} Qt5::Test KF5::AkonadiCore ${grant_lib} KF5::CalendarUtils KF5::CalendarCore KF5::IncidenceEditor KF5::KdepimDBusInterfaces KF5::Libkdepim)
ENDFOREACH(_testname)
ENDMACRO(IE_UNIT_TESTS)
......
......@@ -24,8 +24,11 @@
#include "CalendarSupport/FreeBusyItemModel"
#include "../src/freebusyganttproxymodel.h"
#ifdef KDIAGRAM_SUPPORT
#include <KGantt/KGanttGraphicsView>
#else
#include <KDGantt2/KDGanttGraphicsView>
#endif
#include <KCalCore/Attendee>
#include <qtest.h>
......@@ -80,30 +83,54 @@ void FreeBusyGanttProxyModelTest::testModelValidity()
QModelIndex source_parent0 = fbModel->index(0, 0);
QCOMPARE(parent0.data(), source_parent0.data());
#ifdef KDIAGRAM_SUPPORT
QCOMPARE(parent0.data(KGantt::ItemTypeRole).toInt(), (int) KGantt::TypeMulti);
#else
QCOMPARE(parent0.data(KDGantt::ItemTypeRole).toInt(), (int) KDGantt::TypeMulti);
#endif
QModelIndex source_parent1 = fbModel->index(1, 0);
QCOMPARE(parent1.data(), source_parent1.data());
#ifdef KDIAGRAM_SUPPORT
QCOMPARE(parent1.data(KGantt::ItemTypeRole).toInt(), (int) KGantt::TypeMulti);
#else
QCOMPARE(parent1.data(KDGantt::ItemTypeRole).toInt(), (int) KDGantt::TypeMulti);
#endif
QModelIndex child0_0 = ganttModel->index(0, 0, parent0);
QModelIndex child0_1 = ganttModel->index(1, 0, parent0);
QVERIFY(child0_0.isValid());
QVERIFY(child0_1.isValid());
#ifdef KDIAGRAM_SUPPORT
QCOMPARE(child0_0.data(KGantt::ItemTypeRole).toInt(), (int) KGantt::TypeTask);
QCOMPARE(child0_0.data(KGantt::StartTimeRole).value<QDateTime>(), dt1.dateTime());
QCOMPARE(child0_1.data(KGantt::ItemTypeRole).toInt(), (int) KGantt::TypeTask);
QCOMPARE(child0_1.data(KGantt::StartTimeRole).value<QDateTime>(), dt2.dateTime());
#else
QCOMPARE(child0_0.data(KDGantt::ItemTypeRole).toInt(), (int) KDGantt::TypeTask);
QCOMPARE(child0_0.data(KDGantt::StartTimeRole).value<QDateTime>(), dt1.dateTime());
QCOMPARE(child0_1.data(KDGantt::ItemTypeRole).toInt(), (int) KDGantt::TypeTask);
QCOMPARE(child0_1.data(KDGantt::StartTimeRole).value<QDateTime>(), dt2.dateTime());
#endif
QModelIndex child1_0 = ganttModel->index(0, 0, parent1);
QModelIndex child1_1 = ganttModel->index(1, 0, parent1);
QVERIFY(child1_0.isValid());
QVERIFY(child1_1.isValid());
#ifdef KDIAGRAM_SUPPORT
QCOMPARE(child1_0.data(KGantt::ItemTypeRole).toInt(), (int) KGantt::TypeTask);
QCOMPARE(child1_0.data(KGantt::StartTimeRole).value<QDateTime>(), dt3.dateTime());
QCOMPARE(child1_1.data(KGantt::ItemTypeRole).toInt(), (int) KGantt::TypeTask);
QCOMPARE(child1_1.data(KGantt::StartTimeRole).value<QDateTime>(), dt4.dateTime());
#else
QCOMPARE(child1_0.data(KDGantt::ItemTypeRole).toInt(), (int) KDGantt::TypeTask);
QCOMPARE(child1_0.data(KDGantt::StartTimeRole).value<QDateTime>(), dt3.dateTime());
QCOMPARE(child1_1.data(KDGantt::ItemTypeRole).toInt(), (int) KDGantt::TypeTask);
QCOMPARE(child1_1.data(KDGantt::StartTimeRole).value<QDateTime>(), dt4.dateTime());
#endif
}
......@@ -34,9 +34,11 @@
#include <KCalCore/Event>
#include <KCalCore/MemoryCalendar>
#ifdef KDIAGRAM_SUPPORT
#include <KGantt/KGanttGraphicsView>
#else
#include <KDGantt2/KDGanttGraphicsView>
#endif
#include <akonadi/calendar/freebusymanager.h>
#include <kldap/ldapobject.h>
......
......@@ -51,8 +51,11 @@ using namespace IncidenceEditorNG;
namespace IncidenceEditorNG
{
#ifdef KDIAGRAM_SUPPORT
class RowController : public KGantt::AbstractRowController
#else
class RowController : public KDGantt::AbstractRowController
#endif
{
private:
static const int ROW_HEIGHT;
......@@ -83,11 +86,17 @@ public:
{
return false;
}
#ifdef KDIAGRAM_SUPPORT
KGantt::Span rowGeometry(const QModelIndex &idx) const Q_DECL_OVERRIDE
{
return KGantt::Span(idx.row() * mRowHeight, mRowHeight);
}
#else
KDGantt::Span rowGeometry(const QModelIndex &idx) const Q_DECL_OVERRIDE
{
return KDGantt::Span(idx.row() * mRowHeight, mRowHeight);
}
#endif
int maximumItemHeight() const Q_DECL_OVERRIDE
{
......@@ -173,6 +182,18 @@ VisualFreeBusyWidget::VisualFreeBusyWidget(KPIM::FreeBusyItemModel *model, int s
"and 'Month' shows a range of a few years,<nl/>"
"while 'Automatic' selects the range most "
"appropriate for the current event or to-do."));
#ifdef KDIAGRAM_SUPPORT
mScaleCombo->addItem(i18nc("@item:inlistbox range in hours", "Hour"),
QVariant::fromValue<int>(KGantt::DateTimeGrid::ScaleHour));
mScaleCombo->addItem(i18nc("@item:inlistbox range in days", "Day"),
QVariant::fromValue<int>(KGantt::DateTimeGrid::ScaleDay));
mScaleCombo->addItem(i18nc("@item:inlistbox range in weeks", "Week"),
QVariant::fromValue<int>(KGantt::DateTimeGrid::ScaleWeek));
mScaleCombo->addItem(i18nc("@item:inlistbox range in months", "Month"),
QVariant::fromValue<int>(KGantt::DateTimeGrid::ScaleMonth));
mScaleCombo->addItem(i18nc("@item:inlistbox range is computed automatically", "Automatic"),
QVariant::fromValue<int>(KGantt::DateTimeGrid::ScaleAuto));
#else
mScaleCombo->addItem(i18nc("@item:inlistbox range in hours", "Hour"),
QVariant::fromValue<int>(KDGantt::DateTimeGrid::ScaleHour));
mScaleCombo->addItem(i18nc("@item:inlistbox range in days", "Day"),
......@@ -183,6 +204,7 @@ VisualFreeBusyWidget::VisualFreeBusyWidget(KPIM::FreeBusyItemModel *model, int s
QVariant::fromValue<int>(KDGantt::DateTimeGrid::ScaleMonth));
mScaleCombo->addItem(i18nc("@item:inlistbox range is computed automatically", "Automatic"),
QVariant::fromValue<int>(KDGantt::DateTimeGrid::ScaleAuto));
#endif
mScaleCombo->setCurrentIndex(0); // start with "hour"
connect(mScaleCombo, static_cast<void (KComboBox::*)(int)>(&KComboBox::activated), this, &VisualFreeBusyWidget::slotScaleChanged);
controlLayout->addWidget(mScaleCombo);
......@@ -236,8 +258,11 @@ VisualFreeBusyWidget::VisualFreeBusyWidget(KPIM::FreeBusyItemModel *model, int s
mLeftView->setRootIsDecorated(false);
mLeftView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
mLeftView->setContextMenuPolicy(Qt::CustomContextMenu);
#ifdef KDIAGRAM_SUPPORT
mGanttGraphicsView = new KGantt::GraphicsView(this);
#else
mGanttGraphicsView = new KDGantt::GraphicsView(this);
#endif
mGanttGraphicsView->setObjectName(QStringLiteral("mGanttGraphicsView"));
mGanttGraphicsView->setToolTip(
i18nc("@info:tooltip",
......@@ -257,8 +282,13 @@ VisualFreeBusyWidget::VisualFreeBusyWidget(KPIM::FreeBusyItemModel *model, int s
mRowController->setModel(mModel);
mGanttGraphicsView->setRowController(mRowController);
#ifdef KDIAGRAM_SUPPORT
mGanttGrid = new KGantt::DateTimeGrid;
mGanttGrid->setScale(KGantt::DateTimeGrid::ScaleHour);
#else
mGanttGrid = new KDGantt::DateTimeGrid;
mGanttGrid->setScale(KDGantt::DateTimeGrid::ScaleHour);
#endif
mGanttGrid->setDayWidth(800);
mGanttGrid->setRowSeparators(true);
mGanttGraphicsView->setGrid(mGanttGrid);
......@@ -302,7 +332,11 @@ void VisualFreeBusyWidget::showAttendeeStatusMenu()
void VisualFreeBusyWidget::slotCenterOnStart()
{
#ifdef KDIAGRAM_SUPPORT
KGantt::DateTimeGrid *grid = static_cast<KGantt::DateTimeGrid *>(mGanttGraphicsView->grid());
#else
KDGantt::DateTimeGrid *grid = static_cast<KDGantt::DateTimeGrid *>(mGanttGraphicsView->grid());
#endif
int daysTo = grid->startDateTime().daysTo(mDtStart.dateTime());
mGanttGraphicsView->horizontalScrollBar()->setValue(daysTo * 800);
}
......@@ -328,8 +362,11 @@ void VisualFreeBusyWidget::slotScaleChanged(int newScale)
Q_ASSERT(var.isValid());
int value = var.toInt();
#ifdef KDIAGRAM_SUPPORT
mGanttGrid->setScale((KGantt::DateTimeGrid::Scale)value);
#else
mGanttGrid->setScale((KDGantt::DateTimeGrid::Scale)value);
#endif
}
void VisualFreeBusyWidget::slotUpdateIncidenceStartEnd(const KDateTime &dtFrom,
......@@ -338,7 +375,11 @@ void VisualFreeBusyWidget::slotUpdateIncidenceStartEnd(const KDateTime &dtFrom,
mDtStart = dtFrom;
mDtEnd = dtTo;
QDateTime horizonStart = QDateTime(dtFrom.addDays(-15).date());
#ifdef KDIAGRAM_SUPPORT
KGantt::DateTimeGrid *grid = static_cast<KGantt::DateTimeGrid *>(mGanttGraphicsView->grid());
#else
KDGantt::DateTimeGrid *grid = static_cast<KDGantt::DateTimeGrid *>(mGanttGraphicsView->grid());
#endif
grid->setStartDateTime(horizonStart);
slotCenterOnStart();
mGanttGrid->setStartDateTime(horizonStart);
......
......@@ -25,11 +25,19 @@
#include <QWidget>
#ifdef KDIAGRAM_SUPPORT
namespace KGantt
{
class DateTimeGrid;
class GraphicsView;
}
#else
namespace KDGantt
{
class DateTimeGrid;
class GraphicsView;
}
#endif
namespace KPIM
{
......@@ -71,10 +79,19 @@ private Q_SLOTS:
void splitterMoved();
private:
#ifdef KDIAGRAM_SUPPORT
KGantt::GraphicsView *mGanttGraphicsView;
#else
KDGantt::GraphicsView *mGanttGraphicsView;
#endif
QTreeView *mLeftView;
RowController *mRowController;
#ifdef KDIAGRAM_SUPPORT
KGantt::DateTimeGrid *mGanttGrid;
#else
KDGantt::DateTimeGrid *mGanttGrid;
#endif
KComboBox *mScaleCombo;
FreeBusyGanttProxyModel *mModel;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment