File indexing completed on 2024-11-10 04:40:36
0001 /* 0002 SPDX-FileCopyrightText: 2010 KDAB 0003 SPDX-FileContributor: Tobias Koenig <tokoe@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 namespace Akonadi 0011 { 0012 /** 0013 * @short An interface to report differences between two arbitrary objects. 0014 * 0015 * This interface can be used to report differences between two arbitrary objects 0016 * by describing a virtual table with three columns. The first column contains the name 0017 * of the property that is compared, the second column the property value of the one 0018 * object and the third column the property of the other object. 0019 * 0020 * The rows of this table can have different modes: 0021 * @li NormalMode The left and right columns show the same property values. 0022 * @li ConflictMode The left and right columns show conflicting property values. 0023 * @li AdditionalLeftMode The left column contains a property value that is not available in the right column. 0024 * @li AdditionalRightMode The right column contains a property value that is not available in the left column. 0025 * 0026 * Example: 0027 * 0028 * @code 0029 * // add differences of a contact 0030 * const KContacts::Addressee contact1 = ... 0031 * const KContacts::Addressee contact2 = ... 0032 * 0033 * AbstractDifferencesReporter *reporter = ... 0034 * reporter->setPropertyNameTitle( i18n( "Contact fields" ) ); 0035 * reporter->setLeftPropertyValueTitle( i18n( "Changed Contact" ) ); 0036 * reporter->setRightPropertyValueTitle( i18n( "Conflicting Contact" ) ); 0037 * 0038 * // check given name 0039 * if ( contact1.givenName() != contact2.givenName() ) 0040 * reporter->addProperty( AbstractDifferencesReporter::ConflictMode, i18n( "Given Name" ), 0041 * contact1.givenName(), contact2.givenName() ); 0042 * else 0043 * reporter->addProperty( AbstractDifferencesReporter::NormalMode, i18n( "Given Name" ), 0044 * contact1.givenName(), contact2.givenName() ); 0045 * 0046 * // check family name 0047 * if ( contact1.familyName() != contact2.familyName() ) 0048 * reporter->addProperty( AbstractDifferencesReporter::ConflictMode, i18n( "Family Name" ), 0049 * contact1.givenName(), contact2.givenName() ); 0050 * else 0051 * reporter->addProperty( AbstractDifferencesReporter::NormalMode, i18n( "Family Name" ), 0052 * contact1.givenName(), contact2.givenName() ); 0053 * 0054 * // check emails 0055 * const QStringList leftEmails = contact1.emails(); 0056 * const QStringList rightEmails = contact2.emails(); 0057 * 0058 * for ( const QString &leftEmail : leftEmails ) { 0059 * if ( rightEmails.contains( leftEmail ) ) 0060 * reporter->addProperty( AbstractDifferencesReporter::NormalMode, i18n( "Email" ), 0061 * leftEmail, leftEmail ); 0062 * else 0063 * reporter->addProperty( AbstractDifferencesReporter::AdditionalLeftMode, i18n( "Email" ), 0064 * leftEmail, QString() ); 0065 * } 0066 * 0067 * for( const QString &rightEmail : rightEmails ) { 0068 * if ( !leftEmails.contains( rightEmail ) ) 0069 * reporter->addProperty( AbstractDifferencesReporter::AdditionalRightMode, i18n( "Email" ), 0070 * QString(), rightEmail ); 0071 * } 0072 * 0073 * @endcode 0074 * 0075 * @author Tobias Koenig <tokoe@kde.org> 0076 * @since 4.6 0077 */ 0078 class AbstractDifferencesReporter 0079 { 0080 public: 0081 /** 0082 * Describes the property modes. 0083 */ 0084 enum Mode { 0085 NormalMode, ///< The left and right column show the same property values. 0086 ConflictMode, ///< The left and right column show conflicting property values. 0087 AdditionalLeftMode, ///< The left column contains a property value that is not available in the right column. 0088 AdditionalRightMode ///< The right column contains a property value that is not available in the left column. 0089 }; 0090 0091 /** 0092 * Destroys the abstract differences reporter. 0093 */ 0094 virtual ~AbstractDifferencesReporter() = default; 0095 0096 /** 0097 * Sets the @p title of the property name column. 0098 */ 0099 virtual void setPropertyNameTitle(const QString &title) = 0; 0100 0101 /** 0102 * Sets the @p title of the column that shows the property values 0103 * of the left object. 0104 */ 0105 virtual void setLeftPropertyValueTitle(const QString &title) = 0; 0106 0107 /** 0108 * Sets the @p title of the column that shows the property values 0109 * of the right object. 0110 */ 0111 virtual void setRightPropertyValueTitle(const QString &title) = 0; 0112 0113 /** 0114 * Adds a new property entry to the table. 0115 * 0116 * @param mode Describes the mode of the property. If mode is AdditionalLeftMode or AdditionalRightMode, rightValue resp. leftValue 0117 * should be QString(). 0118 * @param name The user visible name of the property. 0119 * @param leftValue The user visible property value of the left object. 0120 * @param rightValue The user visible property value of the right object. 0121 */ 0122 virtual void addProperty(Mode mode, const QString &name, const QString &leftValue, const QString &rightValue) = 0; 0123 0124 protected: 0125 explicit AbstractDifferencesReporter() = default; 0126 0127 private: 0128 Q_DISABLE_COPY_MOVE(AbstractDifferencesReporter) 0129 }; 0130 0131 }