Permalink
Browse files

Rework on memory management of filter-related objects

  • Loading branch information...
yan12125 authored and agaida committed Oct 11, 2017
1 parent c101e29 commit 0154e036c702b82ebe4b12bed30085247451362c
Showing with 43 additions and 14 deletions.
  1. +31 −5 lib/Filter.cpp
  2. +6 −3 lib/Filter.h
  3. +2 −2 lib/TerminalDisplay.cpp
  4. +1 −1 lib/TerminalDisplay.h
  5. +2 −2 lib/qtermwidget.cpp
  6. +1 −1 lib/qtermwidget.h
@@ -22,6 +22,7 @@

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

// Qt
#include <QAction>
@@ -195,7 +196,15 @@ Filter::~Filter()
}
void Filter::reset()
{
qDeleteAll(_hotspotList);
QListIterator<HotSpot*> iter(_hotspotList);
while (iter.hasNext())
{
HotSpot* currentHotSpot = iter.next();
if (currentHotSpot->hasAnotherParent()) {
continue;
}
delete currentHotSpot;
}
_hotspots.clear();
_hotspotList.clear();
}
@@ -287,10 +296,13 @@ Filter::HotSpot::HotSpot(int startLine , int startColumn , int endLine , int end
, _endLine(endLine)
, _endColumn(endColumn)
, _type(NotSpecified)
, _hasAnotherParent(false)
{
}
QList<QAction*> Filter::HotSpot::actions()
QList<QAction*> Filter::HotSpot::actions(QWidget* parent)
{
Q_UNUSED(parent);

return QList<QAction*>();
}
int Filter::HotSpot::startLine() const
@@ -502,14 +514,28 @@ FilterObject* UrlFilter::HotSpot::getUrlObject() const
return _urlObject;
}

QList<QAction*> UrlFilter::HotSpot::actions()
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)
{
this->_hasAnotherParent = true;
QList<QAction*> list;

const UrlType kind = urlType();

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

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

@@ -115,19 +115,22 @@ 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();
virtual QList<QAction*> actions(QWidget* parent);

bool hasAnotherParent() const { return _hasAnotherParent; }

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. */
@@ -256,7 +259,7 @@ class UrlFilter : public RegExpFilter

FilterObject* getUrlObject() const;

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

/**
* Open a web browser at the current URL. The url itself can be determined using
@@ -1957,14 +1957,14 @@ void TerminalDisplay::mousePressEvent(QMouseEvent* ev)
}
}

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

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

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

void TerminalDisplay::mouseMoveEvent(QMouseEvent* ev)
@@ -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);
QList<QAction*> filterActions(const QPoint& position, QWidget* parent);

/** Returns true if the cursor is set to blink or false otherwise. */
bool blinkingCursor() { return _hasBlinkingCursor; }
@@ -694,9 +694,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)
QList<QAction*> QTermWidget::filterActions(const QPoint& position, QWidget* parent)
{
return m_impl->m_terminalDisplay->filterActions(position);
return m_impl->m_terminalDisplay->filterActions(position, parent);
}

int QTermWidget::getPtySlaveFd() const
@@ -186,7 +186,7 @@ class QTERMWIDGET_EXPORT QTermWidget : public QWidget {
/*
* Proxy for TerminalDisplay::filterActions
* */
QList<QAction*> filterActions(const QPoint& position);
QList<QAction*> filterActions(const QPoint& position, QWidget* parent);

/**
* Returns a pty slave file descriptor.

0 comments on commit 0154e03

Please sign in to comment.