diff --git a/src/autotests/commentparser.cpp b/src/autotests/commentparser.cpp index e56610c..e68e5a0 100644 --- a/src/autotests/commentparser.cpp +++ b/src/autotests/commentparser.cpp @@ -1,376 +1,376 @@ /** * Copyright (C) 2019 Michael Reeves * * This file is part of KDiff3. * * KDiff3 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * KDiff3 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with KDiff3. If not, see . */ #include #include "../CommentParser.h" class CommentParserTest : public QObject { Q_OBJECT - private slots: + private Q_SLOTS: void init() { DefaultCommentParser parser; //Sanity check defaults. QVERIFY(!parser.isPureComment()); QVERIFY(!parser.isEscaped()); QVERIFY(!parser.inString()); QVERIFY(!parser.inComment()); } void singleLineComment() { DefaultCommentParser test; test.processLine("//ddj ?*8"); QVERIFY(!test.inComment()); QVERIFY(test.isPureComment()); //ignore trailing+leading whitespace test = DefaultCommentParser(); test.processLine("\t \t // comment "); QVERIFY(!test.inComment()); QVERIFY(test.isPureComment()); test = DefaultCommentParser(); test.processLine("//comment with quotes embedded \"\""); QVERIFY(!test.inComment()); QVERIFY(test.isPureComment()); test = DefaultCommentParser(); test.processLine("anythis//endof line comment"); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processLine("anythis//ignore embedded multiline sequence /*"); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); } void inComment() { DefaultCommentParser test; test.mCommentType = DefaultCommentParser::multiLine; QVERIFY(test.inComment()); test.mCommentType = DefaultCommentParser::singleLine; QVERIFY(test.inComment()); test.mCommentType = DefaultCommentParser::none; QVERIFY(!test.inComment()); } void multiLineComment() { DefaultCommentParser test; //mutiline syntax on one line test.processLine("/* kjd*/"); QVERIFY(test.isPureComment()); QVERIFY(!test.inComment()); //mid line comment start. test = DefaultCommentParser(); test.processLine("fskk /* kjd */"); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); //mid line comment start. multiple lines test = DefaultCommentParser(); test.processLine("fskk /* kjd "); QVERIFY(test.inComment()); QVERIFY(!test.isPureComment()); test.processLine(" comment line "); QVERIFY(test.inComment()); QVERIFY(test.isPureComment()); test.processLine(" comment */ not comment "); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); //mid line comment start. multiple lines test = DefaultCommentParser(); test.processLine("fskk /* kjd "); QVERIFY(test.inComment()); QVERIFY(!test.isPureComment()); test.processLine(" comment line "); QVERIFY(test.inComment()); QVERIFY(test.isPureComment()); test.processLine(" comment * line / "); QVERIFY(test.inComment()); QVERIFY(test.isPureComment()); //embedded single line character sequence should not end comment test.processLine(" comment line //"); QVERIFY(test.inComment()); QVERIFY(test.isPureComment()); test.processLine(" comment */"); QVERIFY(!test.inComment()); QVERIFY(test.isPureComment()); //Escape squeances not relavate to comments test = DefaultCommentParser(); test.processLine("/* comment \\*/"); QVERIFY(!test.inComment()); QVERIFY(test.isPureComment()); test = DefaultCommentParser(); test.processLine(" int i = 8 / 8 * 3;/* comment*/"); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); //invalid in C++ should not be flagged as pure comment test.processLine("/* comment */ */"); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); //leading whitespace test = DefaultCommentParser(); test.processLine("\t \t /* comment */"); QVERIFY(!test.inComment()); QVERIFY(test.isPureComment()); //trailing whitespace test = DefaultCommentParser(); test.processLine("\t \t /* comment */ "); QVERIFY(!test.inComment()); QVERIFY(test.isPureComment()); } void stringTest() { DefaultCommentParser test; test.processLine("\"quoted string // \""); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processLine("\"quoted string /* \""); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processLine("\"\""); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processChar("\"", '"'); QVERIFY(!test.isEscaped()); QVERIFY(test.inString()); test.processChar("\"'", '\''); QVERIFY(test.inString()); test.processChar("\"'\"", '"'); QVERIFY(!test.inString()); //test only escape sequence we care about test = DefaultCommentParser(); test.processChar("\"", '"'); test.processChar("\"", '\\'); QVERIFY(test.isEscaped()); QVERIFY(test.inString()); test.processChar("\"\\\"", '"'); QVERIFY(!test.isEscaped()); QVERIFY(test.inString()); test.processChar("\"\\\"\"", '"'); QVERIFY(!test.isEscaped()); QVERIFY(!test.inString()); } void quotedCharacter() { DefaultCommentParser test; test.processLine("'\"'"); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test.processLine("'a'"); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test.processLine("'\\\''"); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test.processLine("'*'"); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test.processLine("'/'"); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); } void nonComment() { DefaultCommentParser test; test.processLine(" int i = 8 / 8 * 3;"); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processLine(" "); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processLine(""); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processLine(" / "); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); test = DefaultCommentParser(); test.processLine(" * "); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); //invalid in C++ should not be flagged as non-comment test.processLine(" */"); QVERIFY(!test.inString()); QVERIFY(!test.inComment()); QVERIFY(!test.isPureComment()); } void removeComment() { DefaultCommentParser test; QString line=QLatin1String(" int i = 8 / 8 * 3;"), correct=QLatin1String(" int i = 8 / 8 * 3;"); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); test = DefaultCommentParser(); correct = line = QLatin1String(" //int i = 8 / 8 * 3;"); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); test = DefaultCommentParser(); correct = line = QLatin1String("// int i = 8 / 8 * 3;"); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); test = DefaultCommentParser(); line = QLatin1String(" int i = 8 / 8 * 3;// comment"); correct = QLatin1String(" int i = 8 / 8 * 3; "); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); test = DefaultCommentParser(); line = QLatin1String(" int i = 8 / 8 * 3;/* comment"); correct = QLatin1String(" int i = 8 / 8 * 3; "); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); correct = line = QLatin1String(" int i = 8 / 8 * 3;/* mot a comment"); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); //end comment mid-line line = QLatin1String("d */ why"); correct = QLatin1String(" why"); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); test = DefaultCommentParser(); line = QLatin1String(" int i = 8 / 8 * 3;/* comment*/"); correct = QLatin1String(" int i = 8 / 8 * 3; "); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); test = DefaultCommentParser(); correct = line = QLatin1String(" /*int i = 8 / 8 * 3;/* comment*/"); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); //line with multiple comments weird but legal c/c++ test = DefaultCommentParser(); line = QLatin1String(" int /*why?*/ i = 8 / 8 * 3;/* comment*/"); correct = QLatin1String(" int i = 8 / 8 * 3; "); test.processLine(line); test.removeComment(line); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); //invalid in C++ should not be flagged as non-comment test = DefaultCommentParser(); line = correct = " */"; test.processLine(" */"); QVERIFY(line == correct); QVERIFY(line.length() == correct.length()); } }; QTEST_MAIN(CommentParserTest); #include "commentparser.moc" diff --git a/src/optiondialog.h b/src/optiondialog.h index dc4f9e5..e6b8a1b 100644 --- a/src/optiondialog.h +++ b/src/optiondialog.h @@ -1,135 +1,135 @@ /* * kdiff3 - Text Diff And Merge Tool * Copyright (C) 2002-2007 Joachim Eibl, joachim.eibl at gmx.de * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #ifndef OPTION_DIALOG_H #define OPTION_DIALOG_H #include "options.h" #include // for QSharedPointer #include #include #include #include class QLabel; class QPlainTextEdit; class OptionItemBase; class OptionCheckBox; class OptionEncodingComboBox; class OptionLineEdit; class OptionDialog : public KPageDialog { Q_OBJECT public: explicit OptionDialog( bool bShowDirMergeSettings, QWidget *parent = nullptr ); ~OptionDialog() override; QString parseOptions( const QStringList& optionList ); QString calcOptionHelp(); void saveOptions(KSharedConfigPtr config); void readOptions(KSharedConfigPtr config); void setState(); // Must be called before calling exec(); void addOptionItem(OptionItemBase*); QSharedPointer getOptions() { return m_options; } static const QString s_historyEntryStartRegExpToolTip; static const QString s_historyEntryStartSortKeyOrderToolTip; static const QString s_autoMergeRegExpToolTip; static const QString s_historyStartRegExpToolTip; protected Q_SLOTS: virtual void slotDefault(); virtual void slotOk(); virtual void slotApply(); //virtual void buttonClicked( QAbstractButton* ); virtual void helpRequested(); void slotEncodingChanged(); void slotHistoryMergeRegExpTester(); Q_SIGNALS: void applyDone(); private: void setupFontPage(); void setupColorPage(); void setupEditPage(); void setupDiffPage(); void setupMergePage(); void setupDirectoryMergePage(); void setupRegionalPage(); void setupIntegrationPage(); void setupOtherOptions(); void resetToDefaults(); QSharedPointer m_options=QSharedPointer::create(); //QDialogButtonBox *mButtonBox; OptionCheckBox* m_pSameEncoding; OptionEncodingComboBox* m_pEncodingAComboBox; OptionCheckBox* m_pAutoDetectUnicodeA; OptionEncodingComboBox* m_pEncodingBComboBox; OptionCheckBox* m_pAutoDetectUnicodeB; OptionEncodingComboBox* m_pEncodingCComboBox; OptionCheckBox* m_pAutoDetectUnicodeC; OptionEncodingComboBox* m_pEncodingOutComboBox; OptionCheckBox* m_pAutoSelectOutEncoding; OptionEncodingComboBox* m_pEncodingPPComboBox; OptionCheckBox* m_pHistoryAutoMerge; OptionLineEdit* m_pAutoMergeRegExpLineEdit; OptionLineEdit* m_pHistoryStartRegExpLineEdit; OptionLineEdit* m_pHistoryEntryStartRegExpLineEdit; OptionCheckBox* m_pHistoryMergeSorting; OptionLineEdit* m_pHistorySortKeyOrderLineEdit; }; class FontChooser : public QGroupBox { Q_OBJECT QFont m_font; QPushButton* m_pSelectFont; QPlainTextEdit* m_pExampleTextEdit; QLabel* m_pLabel; public: explicit FontChooser( QWidget* pParent ); QFont font(); void setFont( const QFont&, bool ); -private slots: +private Q_SLOTS: void slotSelectFont(); }; #endif diff --git a/src/progress.h b/src/progress.h index 0f05c9c..8f15e7b 100644 --- a/src/progress.h +++ b/src/progress.h @@ -1,144 +1,144 @@ /*************************************************************************** * Copyright (C) 2003-2007 by Joachim Eibl * * joachim.eibl at gmx.de * * Copyright (C) 2019 Michael Reeves * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef PROGRESS_H #define PROGRESS_H #include #include #include #include class KJob; class QEventLoop; class QLabel; class QProgressBar; class QStatusBar; class ProgressDialog : public QDialog { Q_OBJECT public: ProgressDialog( QWidget* pParent,QStatusBar* ); void setStayHidden( bool bStayHidden ); void setInformation( const QString& info, bool bRedrawUpdate=true ); void setInformation( const QString& info, int current, bool bRedrawUpdate=true ); void setCurrent( qint64 current, bool bRedrawUpdate=true ); void step( bool bRedrawUpdate=true ); void clear(); void setMaxNofSteps(const qint64 dMaxNofSteps); void addNofSteps(const qint64 nofSteps ); void push(); void pop(bool bRedrawUpdate=true); // The progressbar goes from 0 to 1 usually. // By supplying a subrange transformation the subCurrent-values // 0 to 1 will be transformed to dMin to dMax instead. // Requirement: 0 < dMin < dMax < 1 void setRangeTransformation( double dMin, double dMax ); void setSubRangeTransformation( double dMin, double dMax ); void exitEventLoop(); void enterEventLoop( KJob* pJob, const QString& jobInfo ); bool wasCancelled(); enum e_CancelReason{eUserAbort,eResize}; void cancel(e_CancelReason); e_CancelReason cancelReason(); void clearCancelState(); void show(); void hide(); void hideStatusBarWidget(); void delayedHideStatusBarWidget(); void timerEvent(QTimerEvent* event) override; -public slots: +public Q_SLOTS: void recalc(bool bUpdate); private: struct ProgressLevelData { ProgressLevelData() { m_current=0; m_maxNofSteps=1; m_dRangeMin=0; m_dRangeMax=1; m_dSubRangeMin = 0; m_dSubRangeMax = 1; } QAtomicInteger m_current; QAtomicInteger m_maxNofSteps; // when step() is used. double m_dRangeMax; double m_dRangeMin; double m_dSubRangeMax; double m_dSubRangeMin; }; QList m_progressStack; int m_progressDelayTimer; int m_delayedHideTimer; int m_delayedHideStatusBarWidgetTimer; QPointer m_eventLoop; QProgressBar* m_pProgressBar; QProgressBar* m_pSubProgressBar; QLabel* m_pInformation; QLabel* m_pSubInformation; QLabel* m_pSlowJobInfo; QPushButton* m_pAbortButton; QTime m_t1; QTime m_t2; bool m_bWasCancelled; e_CancelReason m_eCancelReason; KJob* m_pJob = nullptr; QString m_currentJobInfo; // Needed if the job doesn't stop after a reasonable time. bool m_bStayHidden; QThread* m_pGuiThread; QStatusBar* m_pStatusBar; // status bar of main window (if exists) QWidget* m_pStatusBarWidget; QProgressBar* m_pStatusProgressBar; QPushButton* m_pStatusAbortButton; protected: void reject() override; -private slots: +private Q_SLOTS: void delayedHide(); void slotAbort(); }; // When using the ProgressProxy you need not take care of the push and pop, except when explicit. class ProgressProxy: public QObject { Q_OBJECT public: ProgressProxy(); ~ProgressProxy() override; void setInformation( const QString& info, bool bRedrawUpdate=true ); void setInformation( const QString& info, int current, bool bRedrawUpdate=true ); void setCurrent( qint64 current, bool bRedrawUpdate=true ); void step( bool bRedrawUpdate=true ); void clear(); void setMaxNofSteps( const qint64 maxNofSteps ); void addNofSteps( const qint64 nofSteps ); bool wasCancelled(); void setRangeTransformation( double dMin, double dMax ); void setSubRangeTransformation( double dMin, double dMax ); static void exitEventLoop(); static void enterEventLoop( KJob* pJob, const QString& jobInfo ); static QDialog *getDialog(); static void recalc(); private: }; extern ProgressDialog* g_pProgressDialog; #endif