Commit 7ea7bef6 authored by Michael Reeves's avatar Michael Reeves

Convert Option* to QSharedPointer<Option>

Using raw pointers across multiple objects is inheriantly risky and fragile
This is why QSharedPointer exists.
parent f653fe76
......@@ -136,7 +136,7 @@ QString MergeFileInfos::fullNameDest() const
return m_dirInfo->destDir().absoluteFilePath() + '/' + subPath();
}
bool MergeFileInfos::compareFilesAndCalcAges(QStringList& errors, Options* const pOptions, DirectoryMergeWindow* pDMW)
bool MergeFileInfos::compareFilesAndCalcAges(QStringList& errors, QSharedPointer<Options> const pOptions, DirectoryMergeWindow* pDMW)
{
std::map<QDateTime, int> dateMap;
......@@ -321,7 +321,7 @@ bool MergeFileInfos::compareFilesAndCalcAges(QStringList& errors, Options* const
bool MergeFileInfos::fastFileComparison(
FileAccess& fi1, FileAccess& fi2,
bool& bError, QString& status, Options* const pOptions)
bool& bError, QString& status, QSharedPointer<Options> const pOptions)
{
ProgressProxy pp;
bool bEqual = false;
......
......@@ -136,7 +136,7 @@ class MergeFileInfos
inline bool isEqualAB() const { return m_bEqualAB; }
inline bool isEqualAC() const { return m_bEqualAC; }
inline bool isEqualBC() const { return m_bEqualBC; }
bool compareFilesAndCalcAges(QStringList& errors, Options* const pOptions, DirectoryMergeWindow* pDMW);
bool compareFilesAndCalcAges(QStringList& errors, QSharedPointer<Options> const pOptions, DirectoryMergeWindow* pDMW);
void updateAge();
......@@ -148,7 +148,7 @@ class MergeFileInfos
inline bool isOperationRunning() const { return !m_bOperationComplete; }
inline void endOperation() { m_bOperationComplete = true; };
private:
bool fastFileComparison(FileAccess& fi1, FileAccess& fi2, bool& bError, QString& status, Options* const pOptions);
bool fastFileComparison(FileAccess& fi1, FileAccess& fi2, bool& bError, QString& status, QSharedPointer<Options> const pOptions);
inline void setAgeA(const e_Age inAge) { m_ageA = inAge; }
inline void setAgeB(const e_Age inAge) { m_ageB = inAge; }
inline void setAgeC(const e_Age inAge) { m_ageC = inAge; }
......
......@@ -20,7 +20,7 @@
#include <QPixmap>
#include <QSize>
Overview::Overview(Options* pOptions)
Overview::Overview(const QSharedPointer<Options> &pOptions)
//: QWidget( pParent, 0, Qt::WNoAutoErase )
{
m_pDiff3LineList = nullptr;
......
......@@ -29,7 +29,7 @@ class Overview : public QWidget
eOMBvsC
};
explicit Overview(Options* pOptions);
explicit Overview(const QSharedPointer<Options> &pOptions);
void init(Diff3LineList* pDiff3LineList, bool bTripleDiff);
void reset();
......@@ -47,7 +47,7 @@ class Overview : public QWidget
private:
const Diff3LineList* m_pDiff3LineList;
Options* m_pOptions;
QSharedPointer<Options> m_pOptions;
bool m_bTripleDiff;
LineRef m_firstLine;
int m_pageHeight;
......
......@@ -97,7 +97,7 @@ bool SourceData::isValid()
return isEmpty() || hasData();
}
void SourceData::setOptions(Options* pOptions)
void SourceData::setOptions(const QSharedPointer<Options> &pOptions)
{
m_pOptions = pOptions;
}
......
......@@ -28,7 +28,7 @@ class SourceData
SourceData();
~SourceData();
void setOptions(Options* pOptions);
void setOptions(const QSharedPointer<Options> &pOptions);
LineRef getSizeLines() const;
qint64 getSizeBytes() const;
......@@ -73,7 +73,7 @@ class SourceData
QTextCodec* detectEncoding(const QString& fileName, QTextCodec* pFallbackCodec);
QString m_aliasName;
FileAccess m_fileAccess;
Options* m_pOptions;
QSharedPointer<Options> m_pOptions;
QString m_tempInputFileName;
QTemporaryFile m_tempFile; //Created from clipboard content.
......
......@@ -538,7 +538,7 @@ bool ManualDiffHelpEntry::isValidMove(int line1, int line2, e_SrcSelector winIdx
}
static bool runDiff(const QVector<LineData>* p1, const qint32 index1, LineRef size1, const QVector<LineData>* p2, const qint32 index2, LineRef size2, DiffList& diffList,
Options* pOptions)
const QSharedPointer<Options> &pOptions)
{
ProgressProxy pp;
static GnuDiff gnuDiff; // All values are initialized with zeros.
......@@ -637,7 +637,7 @@ static bool runDiff(const QVector<LineData>* p1, const qint32 index1, LineRef si
bool ManualDiffHelpList::runDiff(const QVector<LineData>* p1, LineRef size1, const QVector<LineData>* p2, LineRef size2, DiffList& diffList,
e_SrcSelector winIdx1, e_SrcSelector winIdx2,
Options* pOptions)
const QSharedPointer<Options> &pOptions)
{
diffList.clear();
DiffList diffList2;
......
......@@ -392,7 +392,7 @@ class ManualDiffHelpList: public std::list<ManualDiffHelpEntry>
bool runDiff(const QVector<LineData>* p1, LineRef size1, const QVector<LineData>* p2, LineRef size2, DiffList& diffList,
e_SrcSelector winIdx1, e_SrcSelector winIdx2,
Options* pOptions);
const QSharedPointer<Options> &pOptions);
};
void calcDiff(const QString &line1, const QString &line2, DiffList& diffList, int match, int maxSearchRange);
......
......@@ -107,7 +107,7 @@ class DiffTextWindowData
};
QList<QVector<WrapLineCacheData>> m_wrapLineCacheList;
Options* m_pOptions;
QSharedPointer<Options> m_pOptions;
QColor m_cThis;
QColor m_cDiff1;
QColor m_cDiff2;
......@@ -162,7 +162,7 @@ class DiffTextWindowData
DiffTextWindow::DiffTextWindow(
DiffTextWindowFrame* pParent,
QStatusBar* pStatusBar,
Options* pOptions,
const QSharedPointer<Options> &pOptions,
e_SrcSelector winIdx)
: QWidget(pParent)
{
......@@ -1730,7 +1730,7 @@ class DiffTextWindowFrameData
DiffTextWindow* m_pDiffTextWindow;
FileNameLineEdit* m_pFileSelection;
QPushButton* m_pBrowseButton;
Options* m_pOptions;
QSharedPointer<Options> m_pOptions;
QLabel* m_pLabel;
QLabel* m_pTopLine;
QLabel* m_pEncoding;
......@@ -1739,7 +1739,7 @@ class DiffTextWindowFrameData
e_SrcSelector m_winIdx;
};
DiffTextWindowFrame::DiffTextWindowFrame(QWidget* pParent, QStatusBar* pStatusBar, Options* pOptions, e_SrcSelector winIdx, SourceData* psd)
DiffTextWindowFrame::DiffTextWindowFrame(QWidget* pParent, QStatusBar* pStatusBar, const QSharedPointer<Options> &pOptions, e_SrcSelector winIdx, SourceData* psd)
: QWidget(pParent)
{
d = new DiffTextWindowFrameData;
......@@ -1916,7 +1916,7 @@ void DiffTextWindowFrame::sendEncodingChangedSignal(QTextCodec* c)
emit encodingChanged(c);
}
EncodingLabel::EncodingLabel(const QString& text, DiffTextWindowFrame* pDiffTextWindowFrame, SourceData* pSD, Options* pOptions)
EncodingLabel::EncodingLabel(const QString& text, DiffTextWindowFrame* pDiffTextWindowFrame, SourceData* pSD, const QSharedPointer<Options> &pOptions)
: QLabel(text)
{
m_pDiffTextWindowFrame = pDiffTextWindowFrame;
......
......@@ -29,7 +29,7 @@ class DiffTextWindow : public QWidget
{
Q_OBJECT
public:
DiffTextWindow(DiffTextWindowFrame* pParent, QStatusBar* pStatusBar, Options* pOptions, e_SrcSelector winIdx);
DiffTextWindow(DiffTextWindowFrame* pParent, QStatusBar* pStatusBar, const QSharedPointer<Options> &pOptions, e_SrcSelector winIdx);
~DiffTextWindow() override;
void init(
const QString& fileName,
......@@ -110,7 +110,7 @@ class DiffTextWindowFrame : public QWidget
{
Q_OBJECT
public:
DiffTextWindowFrame(QWidget* pParent, QStatusBar* pStatusBar, Options* pOptions, e_SrcSelector winIdx, SourceData* psd);
DiffTextWindowFrame(QWidget* pParent, QStatusBar* pStatusBar, const QSharedPointer<Options> &pOptions, e_SrcSelector winIdx, SourceData* psd);
~DiffTextWindowFrame() override;
DiffTextWindow* getDiffTextWindow();
void init();
......@@ -135,7 +135,7 @@ class EncodingLabel : public QLabel
{
Q_OBJECT
public:
EncodingLabel(const QString& text, DiffTextWindowFrame* pDiffTextWindowFrame, SourceData* psd, Options* pOptions);
EncodingLabel(const QString& text, DiffTextWindowFrame* pDiffTextWindowFrame, SourceData* psd, const QSharedPointer<Options> &pOptions);
protected:
void mouseMoveEvent(QMouseEvent* ev) override;
......@@ -148,7 +148,7 @@ class EncodingLabel : public QLabel
QMenu* m_pContextEncodingMenu;
SourceData* m_pSourceData; //SourceData to get access to "isEmpty()" and "isFromBuffer()" functions
static const int m_maxRecentEncodings = 5;
Options* m_pOptions;
QSharedPointer<Options> m_pOptions;
void insertCodec(const QString& visibleCodecName, QTextCodec* pCodec, QList<int>& CodecEnumList, QMenu* pMenu, int currentTextCodecEnum);
};
......
......@@ -183,7 +183,7 @@ class DirectoryMergeWindow::DirectoryMergeWindowPrivate : public QAbstractItemMo
}
MergeFileInfos* rootMFI() const { return m_pRoot; }
Options* m_pOptions = nullptr;
QSharedPointer<Options> m_pOptions = nullptr;
void calcDirStatus(bool bThreeDirs, const QModelIndex& mi,
int& nofFiles, int& nofDirs, int& nofEqualFiles, int& nofManualMerges);
......@@ -572,7 +572,7 @@ class DirectoryMergeWindow::DirMergeItemDelegate : public QStyledItemDelegate
int i = index == d->m_selection1Index ? 1 : index == d->m_selection2Index ? 2 : index == d->m_selection3Index ? 3 : 0;
if(i != 0)
{
Options* pOpts = d->m_pOptions;
QSharedPointer<Options> pOpts = d->m_pOptions;
QColor c(i == 1 ? pOpts->m_colorA : i == 2 ? pOpts->m_colorB : pOpts->m_colorC);
thePainter->setPen(c); // highlight() );
thePainter->drawRect(x + 2, y + yOffset, icon.width(), icon.height());
......@@ -607,7 +607,7 @@ class DirectoryMergeWindow::DirMergeItemDelegate : public QStyledItemDelegate
}
};
DirectoryMergeWindow::DirectoryMergeWindow(QWidget* pParent, Options* pOptions, KDiff3App* const app)
DirectoryMergeWindow::DirectoryMergeWindow(QWidget* pParent, const QSharedPointer<Options> &pOptions, KDiff3App* const app)
: QTreeView(pParent)
{
d = new DirectoryMergeWindowPrivate(this);
......
......@@ -39,7 +39,7 @@ class DirectoryMergeWindow : public QTreeView
{
Q_OBJECT
public:
DirectoryMergeWindow( QWidget* pParent, Options* pOptions, KDiff3App* const app );
DirectoryMergeWindow( QWidget* pParent, const QSharedPointer<Options> &pOptions, KDiff3App* const app );
~DirectoryMergeWindow() override;
void setDirectoryMergeInfo(DirectoryMergeInfo* p);
bool init(
......
......@@ -137,7 +137,7 @@ KDiff3App::KDiff3App(QWidget* pParent, const QString& name, KDiff3Part* pKDiff3P
connect(m_pOptionDialog, &OptionDialog::applyDone, this, &KDiff3App::slotRefresh);
// This is just a convenience variable to make code that accesses options more readable
m_pOptions = &m_pOptionDialog->m_options;
m_pOptions = m_pOptionDialog->getOptions();
m_pOptionDialog->readOptions(KSharedConfig::openConfig());
......
......@@ -67,7 +67,7 @@ QAction* MergeResultWindow::chooseCForUnsolvedWhiteSpaceConflicts = nullptr;
MergeResultWindow::MergeResultWindow(
QWidget* pParent,
Options* pOptions,
const QSharedPointer<Options> &pOptions,
QStatusBar* pStatusBar)
: QWidget(pParent)
{
......@@ -3084,7 +3084,7 @@ void MergeResultWindow::setSelection(int firstLine, int startPos, int lastLine,
update();
}
WindowTitleWidget::WindowTitleWidget(Options* pOptions)
WindowTitleWidget::WindowTitleWidget(const QSharedPointer<Options> &pOptions)
{
m_pOptions = pOptions;
setAutoFillBackground(true);
......
......@@ -33,7 +33,7 @@ class MergeResultWindow : public QWidget
{
Q_OBJECT
public:
MergeResultWindow(QWidget* pParent, Options* pOptions, QStatusBar* pStatusBar);
MergeResultWindow(QWidget* pParent, const QSharedPointer<Options> &pOptions, QStatusBar* pStatusBar);
void init(
const QVector<LineData>* pLineDataA, LineRef sizeA,
......@@ -139,7 +139,7 @@ private:
static QAction* chooseBForUnsolvedWhiteSpaceConflicts;
static QAction* chooseCForUnsolvedWhiteSpaceConflicts;
Options* m_pOptions = nullptr;
QSharedPointer<Options> m_pOptions = nullptr;
const QVector<LineData>* m_pldA;
const QVector<LineData>* m_pldB;
......@@ -263,9 +263,9 @@ private:
QComboBox* m_pLineEndStyleSelector;
QLabel* m_pEncodingLabel;
QComboBox* m_pEncodingSelector;
Options* m_pOptions;
QSharedPointer<Options> m_pOptions;
public:
explicit WindowTitleWidget(Options* pOptions);
explicit WindowTitleWidget(const QSharedPointer<Options> &pOptions);
QTextCodec* getEncoding();
void setFileName(const QString& fileName);
QString getFileName();
......
This diff is collapsed.
......@@ -51,14 +51,15 @@ public:
QString parseOptions( const QStringList& optionList );
QString calcOptionHelp();
Options m_options;
void saveOptions(KSharedConfigPtr config);
void readOptions(KSharedConfigPtr config);
void setState(); // Must be called before calling exec();
void addOptionItem(OptionItemBase*);
QSharedPointer<Options> getOptions() { return m_options; }
KKeyDialog* m_pKeyDialog;
protected Q_SLOTS:
virtual void slotDefault();
......@@ -72,8 +73,21 @@ protected Q_SLOTS:
Q_SIGNALS:
void applyDone();
private:
void setupFontPage();
void setupColorPage();
void setupEditPage();
void setupDiffPage();
void setupMergePage();
void setupDirectoryMergePage();
void setupKeysPage();
void setupRegionalPage();
void setupIntegrationPage();
void setupOtherOptions();
void resetToDefaults();
QSharedPointer<Options> m_options=QSharedPointer<Options>::create(Options());
std::list<OptionItemBase*> m_optionItemList;
//QDialogButtonBox *mButtonBox;
......@@ -93,18 +107,6 @@ private:
OptionLineEdit* m_pHistoryEntryStartRegExpLineEdit;
OptionCheckBox* m_pHistoryMergeSorting;
OptionLineEdit* m_pHistorySortKeyOrderLineEdit;
private:
void setupFontPage();
void setupColorPage();
void setupEditPage();
void setupDiffPage();
void setupMergePage();
void setupDirectoryMergePage();
void setupKeysPage();
void setupRegionalPage();
void setupIntegrationPage();
void setupOtherOptions();
};
......
......@@ -207,7 +207,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
pp.setInformation(i18n("Diff: A <-> B"));
qCInfo(kdiffMain) << i18n("Diff: A <-> B") ;
m_manualDiffHelpList.runDiff(m_sd1.getLineDataForDiff(), m_sd1.getSizeLines(), m_sd2.getLineDataForDiff(), m_sd2.getSizeLines(), m_diffList12, A, B,
&m_pOptionDialog->m_options);
m_pOptionDialog->getOptions());
pp.step();
......@@ -249,7 +249,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
if(m_sd1.isText() && m_sd2.isText())
{
m_manualDiffHelpList.runDiff(m_sd1.getLineDataForDiff(), m_sd1.getSizeLines(), m_sd2.getLineDataForDiff(), m_sd2.getSizeLines(), m_diffList12, A, B,
&m_pOptionDialog->m_options);
m_pOptionDialog->getOptions());
calcDiff3LineListUsingAB(&m_diffList12, m_diff3LineList);
}
......@@ -258,7 +258,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
if(m_sd1.isText() && m_sd3.isText())
{
m_manualDiffHelpList.runDiff(m_sd1.getLineDataForDiff(), m_sd1.getSizeLines(), m_sd3.getLineDataForDiff(), m_sd3.getSizeLines(), m_diffList13, A, C,
&m_pOptionDialog->m_options);
m_pOptionDialog->getOptions());
calcDiff3LineListUsingAC(&m_diffList13, m_diff3LineList);
correctManualDiffAlignment(m_diff3LineList, &m_manualDiffHelpList);
......@@ -269,7 +269,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, bool bLoadFiles, boo
if(m_sd2.isText() && m_sd3.isText())
{
m_manualDiffHelpList.runDiff(m_sd2.getLineDataForDiff(), m_sd2.getSizeLines(), m_sd3.getLineDataForDiff(), m_sd3.getSizeLines(), m_diffList23, B, C,
&m_pOptionDialog->m_options);
m_pOptionDialog->getOptions());
if(m_pOptions->m_bDiff3AlignBC)
{
calcDiff3LineListUsingBC(&m_diffList23, m_diff3LineList);
......@@ -626,7 +626,7 @@ void KDiff3App::initView()
m_pDiffWindowSplitter->setOrientation(m_pOptions->m_bHorizDiffWindowSplitting ? Qt::Horizontal : Qt::Vertical);
pDiffHLayout->addWidget(m_pDiffWindowSplitter);
m_pOverview = new Overview(&m_pOptionDialog->m_options);
m_pOverview = new Overview(m_pOptionDialog->getOptions());
m_pOverview->setObjectName("Overview");
pDiffHLayout->addWidget(m_pOverview);
connect(m_pOverview, &Overview::setLine, this, &KDiff3App::setDiff3Line);
......@@ -634,11 +634,11 @@ void KDiff3App::initView()
m_pDiffVScrollBar = new QScrollBar(Qt::Vertical, pDiffWindowFrame);
pDiffHLayout->addWidget(m_pDiffVScrollBar);
m_pDiffTextWindowFrame1 = new DiffTextWindowFrame(m_pDiffWindowSplitter, statusBar(), &m_pOptionDialog->m_options, A, &m_sd1);
m_pDiffTextWindowFrame1 = new DiffTextWindowFrame(m_pDiffWindowSplitter, statusBar(), m_pOptionDialog->getOptions(), A, &m_sd1);
m_pDiffWindowSplitter->addWidget(m_pDiffTextWindowFrame1);
m_pDiffTextWindowFrame2 = new DiffTextWindowFrame(m_pDiffWindowSplitter, statusBar(), &m_pOptionDialog->m_options, B, &m_sd2);
m_pDiffTextWindowFrame2 = new DiffTextWindowFrame(m_pDiffWindowSplitter, statusBar(), m_pOptionDialog->getOptions(), B, &m_sd2);
m_pDiffWindowSplitter->addWidget(m_pDiffTextWindowFrame2);
m_pDiffTextWindowFrame3 = new DiffTextWindowFrame(m_pDiffWindowSplitter, statusBar(), &m_pOptionDialog->m_options, C, &m_sd3);
m_pDiffTextWindowFrame3 = new DiffTextWindowFrame(m_pDiffWindowSplitter, statusBar(), m_pOptionDialog->getOptions(), C, &m_sd3);
m_pDiffWindowSplitter->addWidget(m_pDiffTextWindowFrame3);
m_pDiffTextWindow1 = m_pDiffTextWindowFrame1->getDiffTextWindow();
m_pDiffTextWindow2 = m_pDiffTextWindowFrame2->getDiffTextWindow();
......@@ -661,10 +661,10 @@ void KDiff3App::initView()
QVBoxLayout* pMergeVLayout = new QVBoxLayout();
pMergeHLayout->addLayout(pMergeVLayout, 1);
m_pMergeResultWindowTitle = new WindowTitleWidget(&m_pOptionDialog->m_options);
m_pMergeResultWindowTitle = new WindowTitleWidget(m_pOptionDialog->getOptions());
pMergeVLayout->addWidget(m_pMergeResultWindowTitle);
m_pMergeResultWindow = new MergeResultWindow(m_pMergeWindowFrame, &m_pOptionDialog->m_options, statusBar());
m_pMergeResultWindow = new MergeResultWindow(m_pMergeWindowFrame, m_pOptionDialog->getOptions(), statusBar());
pMergeVLayout->addWidget(m_pMergeResultWindow, 1);
m_pMergeVScrollBar = new QScrollBar(Qt::Vertical, m_pMergeWindowFrame);
......@@ -1061,7 +1061,7 @@ void KDiff3App::slotFileOpen()
QDir::toNativeSeparators(m_bDirCompare ? m_dirinfo->dirB().prettyAbsPath() : m_sd2.isFromBuffer() ? QString("") : m_sd2.getAliasName()),
QDir::toNativeSeparators(m_bDirCompare ? m_dirinfo->dirC().prettyAbsPath() : m_sd3.isFromBuffer() ? QString("") : m_sd3.getAliasName()),
m_bDirCompare ? !m_dirinfo->destDir().prettyAbsPath().isEmpty() : !m_outputFilename.isEmpty(),
QDir::toNativeSeparators(m_bDefaultFilename ? QString("") : m_outputFilename), &m_pOptionDialog->m_options));
QDir::toNativeSeparators(m_bDefaultFilename ? QString("") : m_outputFilename), m_pOptionDialog->getOptions()));
int status = d->exec();
if(status == QDialog::Accepted)
......
......@@ -44,7 +44,7 @@
OpenDialog::OpenDialog(
KDiff3App* pParent, const QString& n1, const QString& n2, const QString& n3,
bool bMerge, const QString& outputName, Options* pOptions)
bool bMerge, const QString& outputName, const QSharedPointer<Options> &pOptions)
: QDialog(pParent)
{
setObjectName("OpenDialog");
......
......@@ -35,7 +35,7 @@ class OpenDialog : public QDialog
public:
OpenDialog(// krazy:exclude=explicit
KDiff3App* pParent, const QString& n1, const QString& n2, const QString& n3,
bool bMerge, const QString& outputName, Options* pOptions );
bool bMerge, const QString& outputName, const QSharedPointer<Options> &pOptions );
QComboBox* m_pLineA;
QComboBox* m_pLineB;
......@@ -49,7 +49,7 @@ private:
void selectURL( QComboBox* pLine, bool bDir, int i, bool bSave );
void fixCurrentText(QComboBox* pCB);
Options* m_pOptions;
QSharedPointer<Options> m_pOptions;
bool m_bInputFileNameChanged;
private Q_SLOTS:
void selectFileA();
......
Markdown is supported
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