Akonadi::AbstractDifferencesReporter Class

class Akonadi::AbstractDifferencesReporter

An interface to report differences between two arbitrary objects. More...

Header: #include <Akonadi/AbstractDifferencesReporter>
CMake: find_package(KPim6Akonadi REQUIRED)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore)

Public Types

enum Mode { NormalMode, ConflictMode, AdditionalLeftMode, AdditionalRightMode }

Public Functions

virtual ~AbstractDifferencesReporter()
virtual void addProperty(Akonadi::AbstractDifferencesReporter::Mode mode, const QString &name, const QString &leftValue, const QString &rightValue) = 0
virtual void setLeftPropertyValueTitle(const QString &title) = 0
virtual void setPropertyNameTitle(const QString &title) = 0
virtual void setRightPropertyValueTitle(const QString &title) = 0

Protected Functions

Detailed Description

This interface can be used to report differences between two arbitrary objects by describing a virtual table with three columns. The first column contains the name of the property that is compared, the second column the property value of the one object and the third column the property of the other object.

The rows of this table can have different modes, described by Mode.

Example:

// add differences of a contact
const KContacts::Addressee contact1 = ...;
const KContacts::Addressee contact2 = ...;

AbstractDifferencesReporter *reporter = ...;
reporter->setPropertyNameTitle(i18n("Contact fields"));
reporter->setLeftPropertyValueTitle(i18n("Changed Contact"));
reporter->setRightPropertyValueTitle(i18n("Conflicting Contact"));

// check given name
if (contact1.givenName() != contact2.givenName()) {
    reporter->addProperty(AbstractDifferencesReporter::ConflictMode, i18n("Given Name"), contact1.givenName(), contact2.givenName());
} else {
    reporter->addProperty(AbstractDifferencesReporter::NormalMode, i18n("Given Name"), contact1.givenName(), contact2.givenName());
}

// check family name
if (contact1.familyName() != contact2.familyName()) {
    reporter->addProperty(AbstractDifferencesReporter::ConflictMode, i18n("Family Name"), contact1.familyName(), contact2.familyName());
} else {
    reporter->addProperty(AbstractDifferencesReporter::NormalMode, i18n("Family Name"), contact1.familyName(), contact2.familyName());
}

// check emails
const QStringList leftEmails = contact1.emails();
const QStringList rightEmails = contact2.emails();

for (const QString &leftEmail : leftEmails) {
    if (rightEmails.contains(leftEmail)) {
        reporter->addProperty(AbstractDifferencesReporter::NormalMode, i18n("Email"), leftEmail, leftEmail);
    } else {
        reporter->addProperty(AbstractDifferencesReporter::AdditionalLeftMode, i18n("Email"), leftEmail, QString());
    }
}

for (const QString &rightEmail : rightEmails) {
    if (!leftEmails.contains(rightEmail)) {
        reporter->addProperty(AbstractDifferencesReporter::AdditionalRightMode, i18n("Email"), QString(), rightEmail);
    }
}

Author: Tobias Koenig <tokoe@kde.org>

Member Type Documentation

enum AbstractDifferencesReporter::Mode

Describes the property modes.

ConstantValueDescription
Akonadi::AbstractDifferencesReporter::NormalMode0The left and right columns show the same property values.
Akonadi::AbstractDifferencesReporter::ConflictMode1The left and right columns show conflicting property values.
Akonadi::AbstractDifferencesReporter::AdditionalLeftMode2The left column contains a property value that is not available in the right column.
Akonadi::AbstractDifferencesReporter::AdditionalRightMode3The right column contains a property value that is not available in the left column.

Member Function Documentation

[explicit constexpr noexcept protected default] AbstractDifferencesReporter::AbstractDifferencesReporter()

[virtual constexpr noexcept default] AbstractDifferencesReporter::~AbstractDifferencesReporter()

Destroys the abstract differences reporter.

[pure virtual] void AbstractDifferencesReporter::addProperty(Akonadi::AbstractDifferencesReporter::Mode mode, const QString &name, const QString &leftValue, const QString &rightValue)

Adds a new property entry to the table.

The mode describes the mode of the property. If it is AdditionalLeftMode, rightValue should be an empty QString. If it is AdditionalRightMode, leftValue should be an empty QString.

The name is the user visible name of the property. The leftValue and rightValue are the user visible property values of the left and right objects.

[pure virtual] void AbstractDifferencesReporter::setLeftPropertyValueTitle(const QString &title)

Sets the title of the column that shows the property values of the left object.

[pure virtual] void AbstractDifferencesReporter::setPropertyNameTitle(const QString &title)

Sets the title of the property name column.

[pure virtual] void AbstractDifferencesReporter::setRightPropertyValueTitle(const QString &title)

Sets the title of the column that shows the property values of the right object.