Commit d4f2e55c authored by Josef Weidendorfer's avatar Josef Weidendorfer
Browse files

Preparation for easy porting to Qt6

Allow qcachgrind to compile both with Qt5 and Qt6.
This only changes code which used API already long
deprecated in Qt5 - no need to raise minimum Qt5.3
parent 55e1a9b3
......@@ -24,7 +24,7 @@ void showHelp(QTextStream& out, bool fullHelp = true)
out << "Show profiles from callgrind files. (c) 2010-2016 J. Weidendorfer\n";
if (!fullHelp)
out << "Type 'cgview -h' for help." << endl;
out << "Type 'cgview -h' for help.\n";
else
out << "Usage: cgview [options] <file> ...\n\n"
"Options:\n"
......@@ -33,7 +33,7 @@ void showHelp(QTextStream& out, bool fullHelp = true)
" -s <ev> Sort and show counters for event <ev>\n"
" -c Sort by call count\n"
" -b Show butterfly (callers and callees)\n"
" -n Do not detect recursive cycles" << endl;
" -n Do not detect recursive cycles\n";
exit(1);
}
......@@ -73,7 +73,7 @@ int main(int argc, char** argv)
EventTypeSet* m = d->eventTypes();
if (m->realCount() == 0) {
out << "Error: No event types found." << endl;
out << "Error: No event types found.\n";
return 1;
}
......@@ -97,20 +97,20 @@ int main(int argc, char** argv)
out << " " << et->longName() <<
" (" << et->name() << " = " << et->formula() << ")\n";
}
out << endl;
out << "\n";
if (showEvent.isEmpty())
et = m->realType(0);
else {
et = m->type(showEvent);
if (!et) {
out << "Error: event '" << showEvent << "' not found." << endl;
out << "Error: event '" << showEvent << "' not found.\n";
return 1;
}
}
Q_ASSERT( et!=nullptr );
out << "Sorted by: " << (sortByExcl ? "Exclusive ":"Inclusive ")
<< et->longName() << " (" << et->name() << ")" << endl;
<< et->longName() << " (" << et->name() << ")\n";
QList<TraceFunction*> flist;
HighestCostList hc;
......@@ -141,7 +141,7 @@ int main(int argc, char** argv)
f = (TraceFunction*)hc[i];
if (showCalls) {
if (i>0) out << endl;
if (i>0) out << "\n";
foreach(TraceCall* c, f->callers()) {
out << " ";
out.setFieldWidth(14);
......@@ -151,7 +151,7 @@ int main(int argc, char** argv)
out.setFieldWidth(13);
out << c->prettyCallCount();
out.setFieldWidth(0);
out << " < " << c->caller()->prettyName() << endl;
out << " < " << c->caller()->prettyName() << "\n";
}
}
......@@ -161,7 +161,7 @@ int main(int argc, char** argv)
out.setFieldWidth(13);
out << f->prettyCalledCount();
out.setFieldWidth(0);
out << " " << f->name() << " (" << f->object()->name() << ")" << endl;
out << " " << f->name() << " (" << f->object()->name() << ")" << "\n";
if (showCalls) {
foreach(TraceCall* c, f->callings()) {
......@@ -173,7 +173,7 @@ int main(int argc, char** argv)
out.setFieldWidth(13);
out << c->prettyCallCount();
out.setFieldWidth(0);
out << " > " << c->called()->prettyName() << endl;
out << " > " << c->called()->prettyName() << "\n";
}
}
......
......@@ -354,7 +354,7 @@ TraceObject* CachegrindLoader::compressedObject(const QString& name)
error(QStringLiteral("Invalid compressed ELF object ('%1')").arg(name));
return nullptr;
}
int index = name.midRef(1, p-1).toInt();
int index = name.mid(1, p-1).toInt();
TraceObject* o = nullptr;
p++;
while((name.length()>p) && name.at(p).isSpace()) p++;
......@@ -402,7 +402,7 @@ TraceFile* CachegrindLoader::compressedFile(const QString& name)
error(QStringLiteral("Invalid compressed file ('%1')").arg(name));
return nullptr;
}
int index = name.midRef(1, p-1).toUInt();
int index = name.mid(1, p-1).toUInt();
TraceFile* f = nullptr;
p++;
while((name.length()>p) && name.at(p).isSpace()) p++;
......@@ -455,7 +455,7 @@ TraceFunction* CachegrindLoader::compressedFunction(const QString& name,
}
int index = name.midRef(1, p-1).toUInt();
int index = name.mid(1, p-1).toUInt();
TraceFunction* f = nullptr;
p++;
while((name.length()>p) && name.at(p).isSpace()) p++;
......
......@@ -8,7 +8,7 @@
#include "eventtype.h"
#include <QRegExp>
#include <QRegularExpression>
#include <QDebug>
#include "globalconfig.h"
......@@ -82,26 +82,25 @@ bool EventType::parseFormula()
_coefficient[i] = 0;
_parsedFormula = QString();
QRegExp rx( QStringLiteral("((?:\\+|\\-)?)\\s*(\\d*)\\s*\\*?\\s*(\\w+)") );
QRegularExpression rx( QStringLiteral("((?:\\+|\\-)?)\\s*(\\d*)\\s*\\*?\\s*(\\w+)") );
int factor, pos, found, matching;
int factor, found, matching;
QString costName;
EventType* eventType;
found = 0; // how many types are referenced in formula
matching = 0; // how many types actually are defined in profile data
pos = 0;
while (1) {
pos = rx.indexIn(_formula, pos);
if (pos<0) break;
pos += rx.matchedLength();
if (rx.cap(0).isEmpty()) break;
qsizetype from = 0;
QRegularExpressionMatch match;
while ((from = _formula.indexOf(rx, from, &match)) != -1) {
from += match.capturedLength();
if (match.captured(0).isEmpty()) break;
found++;
//qDebug("parseFormula: matched '%s','%s','%s'",
// qPrintable(rx.cap(1)), qPrintable(rx.cap(2)), qPrintable(rx.cap(3)));
costName = rx.cap(3);
costName = match.captured(3);
eventType = _set->type(costName);
if (!eventType) {
//qDebug("Cost type '%s': In formula cost '%s' unknown.",
......@@ -109,8 +108,8 @@ bool EventType::parseFormula()
continue;
}
factor = (rx.cap(2).isEmpty()) ? 1 : rx.cap(2).toInt();
if (rx.cap(1) == QLatin1String("-")) factor = -factor;
factor = (match.captured(2).isEmpty()) ? 1 : match.captured(2).toInt();
if (match.captured(1) == QLatin1String("-")) factor = -factor;
if (factor == 0) continue;
matching++;
......
......@@ -22,7 +22,7 @@
#include <QFileDialog>
#include <QTemporaryFile>
#include <QTextStream>
#include <QMatrix>
#include <QTransform>
#include <QPair>
#include <QPainter>
#include <QStyle>
......@@ -35,7 +35,7 @@
#include <QContextMenuEvent>
#include <QList>
#include <QPixmap>
#include <QDesktopWidget>
#include <QScreen>
#include <QProcess>
#include <QMenu>
......@@ -226,7 +226,7 @@ TraceCall* GraphNode::visibleCaller()
{
if (0)
qDebug("GraphNode::visibleCaller %s: last %d, count %d",
qPrintable(_f->prettyName()), _lastCallerIndex, callers.count());
qPrintable(_f->prettyName()), _lastCallerIndex, (int) callers.count());
// can not use at(): index can be -1 (out of bounds), result is 0 then
GraphEdge* e = callers.value(_lastCallerIndex);
......@@ -252,7 +252,7 @@ TraceCall* GraphNode::visibleCallee()
{
if (0)
qDebug("GraphNode::visibleCallee %s: last %d, count %d",
qPrintable(_f->prettyName()), _lastCalleeIndex, callees.count());
qPrintable(_f->prettyName()), _lastCalleeIndex, (int) callees.count());
GraphEdge* e = callees.value(_lastCalleeIndex);
if (e && !e->isVisible())
......@@ -970,7 +970,7 @@ TraceFunction* GraphExporter::toFunc(QString s)
if (s[0] != 'F')
return nullptr;
bool ok;
TraceFunction* f = (TraceFunction*) s.midRef(1).toULongLong(&ok, 16);
TraceFunction* f = (TraceFunction*) s.mid(1).toULongLong(&ok, 16);
if (!ok)
return nullptr;
......@@ -1171,7 +1171,7 @@ void PanningView::drawForeground(QPainter * p, const QRectF&)
QColor red(Qt::red);
QPen pen(red.darker());
pen.setWidthF(2.0 / matrix().m11());
pen.setWidthF(2.0 / transform().m11());
p->setPen(pen);
QColor c(red.darker());
......@@ -1666,8 +1666,8 @@ void CallGraphView::updateSizes(QSize s)
qDebug("Canvas Size: %fx%f, Content: %dx%d, Zoom: %f",
_scene->width(), _scene->height(), cWidth, cHeight, zoom);
QMatrix m;
_panningView->setMatrix(m.scale(zoom, zoom));
QTransform m;
_panningView->setTransform(m.scale(zoom, zoom));
// make it a little bigger to compensate for widget frame
_panningView->resize(int(cWidth * zoom) + 4, int(cHeight * zoom) + 4);
......@@ -2270,12 +2270,12 @@ void CallGraphView::dotExited()
// We use as minimum canvas size the desktop size.
// Otherwise, the canvas would have to be resized on widget resize.
_xMargin = 50;
if (w < QApplication::desktop()->width())
_xMargin += (QApplication::desktop()->width()-w)/2;
if (w < QApplication::primaryScreen()->size().width())
_xMargin += (QApplication::primaryScreen()->size().width()-w)/2;
_yMargin = 50;
if (h < QApplication::desktop()->height())
_yMargin += (QApplication::desktop()->height()-h)/2;
if (h < QApplication::primaryScreen()->size().height())
_yMargin += (QApplication::primaryScreen()->size().height()-h)/2;
_scene = new QGraphicsScene( 0.0, 0.0,
qreal(w+2*_xMargin), qreal(h+2*_yMargin));
......
......@@ -11,6 +11,29 @@
#include "globalguiconfig.h"
#include "listutils.h"
/* helper for setting function filter: we want it to work similar to globbing:
* - escape most special characters in regexps: ( ) [ ] | . \
* - change * to .*
*/
QString glob2Regex(QString pattern)
{
pattern.replace(QChar('\\'),QLatin1String("\\\\"));
pattern.replace(QChar('('),QLatin1String("\\("));
pattern.replace(QChar(')'),QLatin1String("\\)"));
pattern.replace(QChar('['),QLatin1String("\\["));
pattern.replace(QChar(']'),QLatin1String("\\]"));
pattern.replace(QChar('|'),QLatin1String("\\|"));
pattern.replace(QChar('.'),QLatin1String("\\."));
pattern.replace(QChar('*'),QLatin1String(".*"));
return pattern;
}
//
// FunctionListModel
//
FunctionListModel::FunctionListModel()
: QAbstractItemModel(nullptr)
{
......@@ -178,7 +201,8 @@ void FunctionListModel::setFilter(QString filterString)
if (_filterString == filterString) return;
_filterString = filterString;
_filter = QRegExp(_filterString, Qt::CaseInsensitive, QRegExp::Wildcard);
_filter = QRegularExpression(glob2Regex(_filterString),
QRegularExpression::CaseInsensitiveOption);
computeFilteredList();
computeTopList();
}
......@@ -259,7 +283,8 @@ void FunctionListModel::resetModelData(TraceData *data,
}
_filterString = filterString;
_filter = QRegExp(_filterString, Qt::CaseInsensitive, QRegExp::Wildcard);
_filter = QRegularExpression(glob2Regex(_filterString),
QRegularExpression::CaseInsensitiveOption);
computeFilteredList();
computeTopList();
......@@ -279,8 +304,8 @@ void FunctionListModel::computeFilteredList()
_filteredList.clear();
int index = 0;
foreach(TraceFunction* f, _list) {
if (!_filterString.isEmpty())
if (_filter.indexIn(f->name()) == -1) continue;
if (!_filterString.isEmpty() && _filter.isValid())
if (!f->name().contains(_filter)) continue;
_filteredList.append(f);
if (!_max0 || lessThan0(_max0, f)) { _max0 = f; }
......
......@@ -11,12 +11,14 @@
#include <QAbstractItemModel>
#include <QPixmap>
#include <QRegExp>
#include <QRegularExpression>
#include <QList>
#include "tracedata.h"
#include "subcost.h"
// helper for setting function filter
QString glob2Regex(QString pattern);
class FunctionListModel : public QAbstractItemModel
{
......@@ -98,7 +100,7 @@ private:
int _sortColumn;
Qt::SortOrder _sortOrder;
QRegExp _filter;
QRegularExpression _filter;
QString _filterString;
};
......
......@@ -16,7 +16,7 @@
#include <QPushButton>
#include <QComboBox>
#include <QLineEdit>
#include <QRegExp>
#include <QRegularExpression>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QAction>
......@@ -800,7 +800,8 @@ void FunctionSelection::query(QString query)
}
_searchString = query;
QRegExp re(query, Qt::CaseInsensitive, QRegExp::Wildcard);
QRegularExpression re(glob2Regex(query),
QRegularExpression::CaseInsensitiveOption);
_groupSize.clear();
TraceFunction* f = nullptr;
......@@ -812,7 +813,7 @@ void FunctionSelection::query(QString query)
for ( it = _data->functionMap().begin();
it != _data->functionMap().end(); ++it ) {
f = &(*it);
if (re.indexIn(f->prettyName())>=0) {
if (re.isValid() && f->prettyName().contains(re)) {
if (_group) {
if (_groupType==ProfileContext::Object) {
if (_groupSize.contains(f->object()))
......
......@@ -981,7 +981,7 @@ bool InstrView::fillInstrRange(TraceFunction* function,
if (0) qDebug() << "Check if 0x" << addr.toString() << " is in ]0x"
<< costAddr.toString() << ",0x"
<< (nextCostAddr - 3*GlobalConfig::noCostInside()).toString()
<< "[" << endl;
<< "[";
// Suppose a average instruction len of 3 bytes
if ( (addr > costAddr) &&
......
......@@ -14,7 +14,7 @@
#include <QFontDatabase>
#include <QPixmap>
#include <QRegExp>
#include <QRegularExpression>
#include <QPainter>
#include <QPolygon>
#include <QTextDocument>
......@@ -54,7 +54,7 @@ SourceItem::SourceItem(SourceView* sv, QTreeWidget* parent,
setText(0, QString::number(lineno));
QString s = src;
setText(4, s.replace( QRegExp(QStringLiteral("\t")), QStringLiteral(" ") ));
setText(4, s.replace( QStringLiteral("\t"), QStringLiteral(" ") ));
QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
setFont(4, font); // the source code line
......
......@@ -6,8 +6,10 @@ lessThan(QT_MAJOR_VERSION, 5) {
error("QCachegrind requires Qt 5.3 or greater")
}
lessThan(QT_MINOR_VERSION, 3) {
error("QCachegrind requires Qt 5.3 or greater")
lessThan(QT_MAJOR_VERSION, 6) {
lessThan(QT_MINOR_VERSION, 3) {
error("QCachegrind requires Qt 5.3 or greater")
}
}
......
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