Skip to content

Commit

Permalink
Revert "Rework on memory management of filter-related objects"
Browse files Browse the repository at this point in the history
This reverts commit 0154e03.
  • Loading branch information
Chih-Hsuan Yen authored and Chih-Hsuan Yen committed Jan 14, 2019
1 parent f475050 commit b09e1d4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 41 deletions.
35 changes: 6 additions & 29 deletions lib/Filter.cpp
Expand Up @@ -22,7 +22,6 @@

// System
#include <iostream>
#include <memory>

// Qt
#include <QAction>
Expand Down Expand Up @@ -193,12 +192,7 @@ Filter::~Filter()
}
void Filter::reset()
{
for (HotSpot* const currentHotSpot : qAsConst(_hotspotList)) {
if (currentHotSpot->hasAnotherParent()) {
continue;
}
delete currentHotSpot;
}
qDeleteAll(_hotspotList);
_hotspots.clear();
_hotspotList.clear();
}
Expand Down Expand Up @@ -285,18 +279,15 @@ Filter::HotSpot* Filter::hotSpotAt(int line , int column) const
}

Filter::HotSpot::HotSpot(int startLine , int startColumn , int endLine , int endColumn)
: _hasAnotherParent(false)
, _startLine(startLine)
: _startLine(startLine)
, _startColumn(startColumn)
, _endLine(endLine)
, _endColumn(endColumn)
, _type(NotSpecified)
{
}
QList<QAction*> Filter::HotSpot::actions(QWidget* parent)
QList<QAction*> Filter::HotSpot::actions()
{
Q_UNUSED(parent);

return QList<QAction*>();
}
int Filter::HotSpot::startLine() const
Expand Down Expand Up @@ -508,28 +499,14 @@ FilterObject* UrlFilter::HotSpot::getUrlObject() const
return _urlObject;
}

class UrlAction : public QAction {
public:
UrlAction(QWidget* parent, std::shared_ptr<UrlFilter::HotSpot> hotspotPtr)
: QAction(parent)
, _hotspotPtr(hotspotPtr)
{
}

private:
std::shared_ptr<UrlFilter::HotSpot> _hotspotPtr;
};

QList<QAction*> UrlFilter::HotSpot::actions(QWidget* parent)
QList<QAction*> UrlFilter::HotSpot::actions()
{
this->_hasAnotherParent = true;
QList<QAction*> list;

const UrlType kind = urlType();

std::shared_ptr<UrlFilter::HotSpot> hotspotPtr(this);
UrlAction* openAction = new UrlAction(parent, hotspotPtr);
UrlAction* copyAction = new UrlAction(parent, hotspotPtr);
QAction* openAction = new QAction(_urlObject);
QAction* copyAction = new QAction(_urlObject);;

Q_ASSERT( kind == StandardUrl || kind == Email );

Expand Down
9 changes: 3 additions & 6 deletions lib/Filter.h
Expand Up @@ -115,22 +115,19 @@ class Filter : public QObject
* Returns a list of actions associated with the hotspot which can be used in a
* menu or toolbar
*/
virtual QList<QAction*> actions(QWidget* parent);

bool hasAnotherParent() const { return _hasAnotherParent; }
virtual QList<QAction*> actions();

protected:
/** Sets the type of a hotspot. This should only be set once */
void setType(Type type);

bool _hasAnotherParent;

private:
int _startLine;
int _startColumn;
int _endLine;
int _endColumn;
Type _type;

};

/** Constructs a new filter. */
Expand Down Expand Up @@ -259,7 +256,7 @@ class UrlFilter : public RegExpFilter

FilterObject* getUrlObject() const;

virtual QList<QAction*> actions(QWidget* parent);
virtual QList<QAction*> actions();

/**
* Open a web browser at the current URL. The url itself can be determined using
Expand Down
4 changes: 2 additions & 2 deletions lib/TerminalDisplay.cpp
Expand Up @@ -1962,14 +1962,14 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
}
}

QList<QAction*> TerminalDisplay::filterActions(const QPoint& position, QWidget* parent)
QList<QAction*> TerminalDisplay::filterActions(const QPoint& position)
{
int charLine, charColumn;
getCharacterPosition(position,charLine,charColumn);

Filter::HotSpot* spot = _filterChain->hotSpotAt(charLine,charColumn);

return spot ? spot->actions(parent) : QList<QAction*>();
return spot ? spot->actions() : QList<QAction*>();
}

void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
Expand Down
2 changes: 1 addition & 1 deletion lib/TerminalDisplay.h
Expand Up @@ -158,7 +158,7 @@ class KONSOLEPRIVATE_EXPORT TerminalDisplay : public QWidget
* Returns a list of menu actions created by the filters for the content
* at the given @p position.
*/
QList<QAction*> filterActions(const QPoint& position, QWidget* parent);
QList<QAction*> filterActions(const QPoint& position);

/** Returns true if the cursor is set to blink or false otherwise. */
bool blinkingCursor() { return _hasBlinkingCursor; }
Expand Down
4 changes: 2 additions & 2 deletions lib/qtermwidget.cpp
Expand Up @@ -671,9 +671,9 @@ Filter::HotSpot* QTermWidget::getHotSpotAt(int row, int column) const
return m_impl->m_terminalDisplay->filterChain()->hotSpotAt(row, column);
}

QList<QAction*> QTermWidget::filterActions(const QPoint& position, QWidget* parent)
QList<QAction*> QTermWidget::filterActions(const QPoint& position)
{
return m_impl->m_terminalDisplay->filterActions(position, parent);
return m_impl->m_terminalDisplay->filterActions(position);
}

int QTermWidget::getPtySlaveFd() const
Expand Down
2 changes: 1 addition & 1 deletion lib/qtermwidget.h
Expand Up @@ -186,7 +186,7 @@ class QTERMWIDGET_EXPORT QTermWidget : public QWidget {
/*
* Proxy for TerminalDisplay::filterActions
* */
QList<QAction*> filterActions(const QPoint& position, QWidget* parent);
QList<QAction*> filterActions(const QPoint& position);

/**
* Returns a pty slave file descriptor.
Expand Down

0 comments on commit b09e1d4

Please sign in to comment.