Krita Source Code Documentation
Loading...
Searching...
No Matches
KisChangeGuidesCommand::Private Struct Reference

Public Types

enum  Status {
  NO_DIFF = 0 , ONE_DIFF = 1 , ADDITION = 4 , REMOVAL = 16 ,
  OTHER_DIFF = 1024
}
 

Public Member Functions

Status diff (const QList< qreal > &first, const QList< qreal > &second)
 
 Private (KisDocument *_doc, KisChangeGuidesCommand *q)
 
bool sameOrOnlyMovedOneGuideBetween (const KisGuidesConfig &first, const KisGuidesConfig &second)
 
void switchTo (const KisGuidesConfig &config)
 

Public Attributes

KisDocumentdoc
 
bool firstRedo
 
KisGuidesConfig newGuides
 
KisGuidesConfig oldGuides
 
KisChangeGuidesCommandq
 

Detailed Description

Definition at line 16 of file kis_change_guides_command.cpp.

Member Enumeration Documentation

◆ Status

Constructor & Destructor Documentation

◆ Private()

KisChangeGuidesCommand::Private::Private ( KisDocument * _doc,
KisChangeGuidesCommand * q )
inline

Member Function Documentation

◆ diff()

KisChangeGuidesCommand::Private::Status KisChangeGuidesCommand::Private::diff ( const QList< qreal > & first,
const QList< qreal > & second )

Definition at line 59 of file kis_change_guides_command.cpp.

60{
61 if (first.size() == second.size()) {
62 int diffCount = 0;
63 for (int i = 0; i < first.size(); ++i) {
64 if (first[i] != second[i]) {
65 ++diffCount;
66 if (diffCount > 1) {
67 return OTHER_DIFF;
68 }
69 }
70 }
71 return diffCount == 0 ? NO_DIFF : ONE_DIFF;
72 } else if (first.size() - second.size() == -1) { // added a guide
73 QList<qreal> beforeRemoval = second;
74 beforeRemoval.takeLast();
75 return first == beforeRemoval ? ADDITION : OTHER_DIFF;
76 } else if (first.size() - second.size() == 1) { // removed a guide
77 bool skippedItem = false;
78 for (QListIterator<qreal> i(first), j(second); i.hasNext() && j.hasNext(); ) {
79 qreal curFirst = i.next();
80 qreal curSecond = j.next();
81 if (!skippedItem && curFirst != curSecond) {
82 curFirst = i.next(); // try to go to the next item and see if it matches
83 }
84 if (curFirst != curSecond) {
85 return OTHER_DIFF;
86 }
87 }
88 // here we conclude only one guide is removed
89 return REMOVAL;
90 } else {
91 return OTHER_DIFF;
92 }
93}

◆ sameOrOnlyMovedOneGuideBetween()

bool KisChangeGuidesCommand::Private::sameOrOnlyMovedOneGuideBetween ( const KisGuidesConfig & first,
const KisGuidesConfig & second )

Definition at line 41 of file kis_change_guides_command.cpp.

42{
43 int ret = diff(first.horizontalGuideLines(), second.horizontalGuideLines()) +
45
46 if (ret == ADDITION) {
47 q->setText(kundo2_i18n("Add Guide"));
48 } else if (ret == REMOVAL) {
49 q->setText(kundo2_i18n("Remove Guide"));
50 } else if (ret == NO_DIFF || ret == ONE_DIFF) { // meaning we will still merge it
51 // XXX: how to deal with NO_DIFF (the command "should" be removed -- how?)
52 q->setText(kundo2_i18n("Edit Guides"));
53 } else {
54 return false;
55 }
56 return true;
57}
void setText(const KUndo2MagicString &text)
const QList< qreal > & verticalGuideLines() const
Returns the list of vertical guide lines.
const QList< qreal > & horizontalGuideLines() const
Returns the list of horizontal guide lines.
KUndo2MagicString kundo2_i18n(const char *text)
Status diff(const QList< qreal > &first, const QList< qreal > &second)

References ADDITION, diff(), KisGuidesConfig::horizontalGuideLines(), kundo2_i18n(), NO_DIFF, ONE_DIFF, q, REMOVAL, KUndo2Command::setText(), and KisGuidesConfig::verticalGuideLines().

◆ switchTo()

void KisChangeGuidesCommand::Private::switchTo ( const KisGuidesConfig & config)

Definition at line 95 of file kis_change_guides_command.cpp.

96{
97 KisGuidesConfig curConfig = doc->guidesConfig();
99 curConfig.setVerticalGuideLines(config.verticalGuideLines());
100 doc->setGuidesConfig(curConfig);
101}
void setGuidesConfig(const KisGuidesConfig &data)
KisGuidesConfig guidesConfig
void setHorizontalGuideLines(const QList< qreal > &lines)
Set the positions of the horizontal guide lines.
void setVerticalGuideLines(const QList< qreal > &lines)
Set the positions of the vertical guide lines.

References KisGuidesConfig::horizontalGuideLines(), KisGuidesConfig::setHorizontalGuideLines(), KisGuidesConfig::setVerticalGuideLines(), and KisGuidesConfig::verticalGuideLines().

Member Data Documentation

◆ doc

KisDocument* KisChangeGuidesCommand::Private::doc

Definition at line 32 of file kis_change_guides_command.cpp.

◆ firstRedo

bool KisChangeGuidesCommand::Private::firstRedo

Definition at line 38 of file kis_change_guides_command.cpp.

◆ newGuides

KisGuidesConfig KisChangeGuidesCommand::Private::newGuides

Definition at line 36 of file kis_change_guides_command.cpp.

◆ oldGuides

KisGuidesConfig KisChangeGuidesCommand::Private::oldGuides

Definition at line 35 of file kis_change_guides_command.cpp.

◆ q

KisChangeGuidesCommand* KisChangeGuidesCommand::Private::q

Definition at line 33 of file kis_change_guides_command.cpp.


The documentation for this struct was generated from the following file: