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

QCachegrind: config page for base directories of source files

This looks nicer than the config dialog of KCachegrind itself
now, so I will probably use it for both if all the functionality
is there.
Especially, one can jump now to specific places in the config
dialog via a string. So we can connect context menu items to
specific views to config pages. This is a start to move all
the view config hiding in context menues into a config page.

Anyway, missing from KCachegrind configuration now only are
the color settings for cost items. However, I actually never
changed a color, so probably also nobody else...

svn path=/trunk/KDE/kdesdk/kcachegrind/; revision=1048836
parent e5ed951a
......@@ -545,3 +545,29 @@ void GlobalConfig::setContext(int v)
if ((v<1) || (v >500)) return;
_context = v;
}
const QStringList& GlobalConfig::generalSourceDirs()
{
return _generalSourceDirs;
}
QStringList GlobalConfig::objectSourceDirs(QString obj)
{
if (_objectSourceDirs.contains(obj))
return _objectSourceDirs[obj];
else
return QStringList();
}
void GlobalConfig::setGeneralSourceDirs(QStringList dirs)
{
_generalSourceDirs = dirs;
}
void GlobalConfig::setObjectSourceDirs(QString obj, QStringList dirs)
{
if (dirs.count() == 0)
_objectSourceDirs.remove(obj);
else
_objectSourceDirs.insert(obj, dirs);
}
......@@ -71,6 +71,11 @@ public:
// how many lines without cost are still regarded as inside a function
static int noCostInside();
const QStringList& generalSourceDirs();
QStringList objectSourceDirs(QString);
void setGeneralSourceDirs(QStringList);
void setObjectSourceDirs(QString, QStringList);
void setPercentPrecision(int);
void setMaxSymbolLength(int);
void setMaxSymbolCount(int);
......
......@@ -2,10 +2,10 @@ include_directories(../libcore ../libviews)
set(qcachegrind_SRCS qcgmain.cpp qcgtoplevel.cpp qcgconfig.cpp
configdialog.cpp configpage.cpp
generalsettings.cpp)
generalsettings.cpp sourcesettings.cpp)
qt4_automoc(${qcachegrind_SRCS})
qt4_wrap_ui(qcachegrind_H generalsettings.ui)
qt4_wrap_ui(qcachegrind_H generalsettings.ui sourcesettings.ui)
qt4_add_resources(qcachegrind_RSRC qcachegrind.qrc)
add_executable(qcachegrind ${qcachegrind_SRCS} ${qcachegrind_H} ${qcachegrind_RSRC})
......
......@@ -33,18 +33,19 @@
#include <QTimer>
#include "generalsettings.h"
#include "sourcesettings.h"
//
// ConfigDialog
//
ConfigDialog::ConfigDialog(TraceData* /*data*/, QWidget* parent, QString s)
ConfigDialog::ConfigDialog(TraceData* data, QWidget* parent, QString s)
: QDialog(parent)
{
setWindowTitle(tr("Configure QCachegrind"));
_listWidget = new QListWidget(this);
_listWidget->setMaximumWidth(100);
_listWidget->setMaximumWidth(140);
_widgetStack = new QStackedWidget(this);
_titleLabel = new QLabel(this);
QFont labelFont;
......@@ -81,6 +82,7 @@ ConfigDialog::ConfigDialog(TraceData* /*data*/, QWidget* parent, QString s)
connect(&_clearTimer, SIGNAL(timeout()), this, SLOT(clearError()));
addPage(new GeneralSettings(this));
addPage(new SourceSettings(data, this));
activate(s);
}
......@@ -135,6 +137,11 @@ void ConfigDialog::activate(QString s)
}
}
QString ConfigDialog::currentPage()
{
return _listWidget->currentItem()->text();
}
void ConfigDialog::accept()
{
ConfigPage* p;
......
......@@ -46,6 +46,7 @@ public:
ConfigDialog(TraceData* data, QWidget* parent, QString s = QString::null);
void activate(QString);
QString currentPage();
public slots:
void accept();
......
......@@ -26,13 +26,14 @@ new_moc.input = NHEADERS
QMAKE_EXTRA_COMPILERS = new_moc
# Input
FORMS += generalsettings.ui
FORMS += generalsettings.ui sourcesettings.ui
NHEADERS += qcgconfig.h \
qcgtoplevel.h \
configdialog.h \
configpage.h \
generalsettings.h \
sourcesettings.h \
../libcore/context.h \
../libcore/costitem.h \
../libcore/subcost.h \
......@@ -82,6 +83,7 @@ SOURCES += qcgmain.cpp \
configdialog.cpp \
configpage.cpp \
generalsettings.cpp \
sourcesettings.cpp \
../libcore/context.cpp \
../libcore/costitem.cpp \
../libcore/subcost.cpp \
......
......@@ -641,12 +641,17 @@ void QCGTopLevel::about()
void QCGTopLevel::configure(QString s)
{
static QString lastPage = QString::null;
// if no specific config item should be focussed, use last page
if (s.isEmpty()) s = lastPage;
ConfigDialog d(_data, this, s);
if (d.exec() == QDialog::Accepted) {
GlobalConfig::config()->saveOptions();
configChanged();
}
lastPage = d.currentPage();
}
void QCGTopLevel::togglePartDock()
......
/* This file is part of KCachegrind.
Copyright (C) 2009 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
KCachegrind 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, version 2.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/*
* Source annotation directory settings config page
*/
#include <QTreeWidgetItem>
#include <QFileDialog>
#include "tracedata.h"
#include "sourcesettings.h"
#include "globalconfig.h"
//
// SourceSettings
//
SourceSettings::SourceSettings(TraceData* data, QWidget* parent)
: ConfigPage(parent,
QObject::tr("Source Annotation"),
QObject::tr("Directory Settings for Source Annotation"))
{
ui.setupUi(this);
ui.dirList->setRootIsDecorated(false);
GlobalConfig* c = GlobalConfig::config();
_always = tr("(always)");
QTreeWidgetItem* i;
QStringList::const_iterator sit = c->generalSourceDirs().constBegin();
for(; sit != c->generalSourceDirs().constEnd(); ++sit ) {
QString d = (*sit);
if (d.isEmpty()) d = "/";
i = new QTreeWidgetItem();
i->setText(0, _always);
i->setText(1, d);
ui.dirList->addTopLevelItem(i);
}
QStringList objItems(_always);
if (data) {
TraceObjectMap::Iterator oit;
for ( oit = data->objectMap().begin();
oit != data->objectMap().end(); ++oit ) {
QString n = (*oit).name();
if (n.isEmpty()) continue;
objItems << n;
const QStringList& dirs = c->objectSourceDirs(n);
sit = dirs.constBegin();
for(; sit != dirs.constEnd(); ++sit ) {
QString d = (*sit);
if (d.isEmpty()) d = "/";
i = new QTreeWidgetItem();
i->setText(0, n);
i->setText(1, d);
ui.dirList->addTopLevelItem(i);
}
}
}
ui.objectBox->addItems(objItems);
ui.objectBox->setCurrentIndex(0);
connect(ui.addDirButton, SIGNAL(clicked()),
this, SLOT(addClicked()));
connect(ui.deleteDirButton, SIGNAL(clicked()),
this, SLOT(deleteClicked()));
connect(ui.browseDirButton, SIGNAL(clicked()),
this, SLOT(browseClicked()));
connect(ui.dirList,
SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)),
this,
SLOT(dirListItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
connect(ui.objectBox,
SIGNAL(currentIndexChanged(QString)),
this, SLOT(objectChanged(QString)));
connect(ui.dirEdit, SIGNAL(textChanged(QString)),
this, SLOT(dirEditChanged(QString)));
_current = 0;
update();
}
void SourceSettings::activate(QString s)
{
int idx = s.toInt();
if ((idx==0) || (idx>ui.dirList->topLevelItemCount())) return;
ui.dirList->setCurrentItem(ui.dirList->topLevelItem(idx-1));
ui.dirEdit->setFocus();
}
void SourceSettings::update()
{
if (!_current) {
ui.deleteDirButton->setEnabled(false);
ui.objectBox->setEnabled(false);
ui.dirEdit->setEnabled(false);
ui.browseDirButton->setEnabled(false);
return;
}
ui.deleteDirButton->setEnabled(true);
ui.objectBox->setEnabled(true);
ui.objectBox->setCurrentIndex(ui.objectBox->findText(_current->text(0)));
ui.dirEdit->setEnabled(true);
ui.dirEdit->setText(_current->text(1));
ui.browseDirButton->setEnabled(true);
}
void SourceSettings::addClicked()
{
QTreeWidgetItem* i = new QTreeWidgetItem();
i->setText(0, ui.objectBox->currentText());
i->setText(1, tr("<insert valid directory>"));
ui.dirList->addTopLevelItem(i);
ui.dirList->setCurrentItem(i);
}
void SourceSettings::deleteClicked()
{
if (!_current) return;
QTreeWidgetItem* i = _current;
// the deletion removes the item
delete _current;
// deletion can trigger a call to dirListItemChanged() !
if (_current == i) {
_current = 0;
update();
}
}
void SourceSettings::browseClicked()
{
QString d;
d = QFileDialog::getExistingDirectory(this,
tr("Choose Source Directory"));
if (!d.isEmpty())
ui.dirEdit->setText(d);
}
void SourceSettings::dirListItemChanged(QTreeWidgetItem* current,
QTreeWidgetItem*)
{
_current = current;
update();
}
void SourceSettings::objectChanged(QString obj)
{
if (!_current) return;
_current->setText(0, obj);
}
void SourceSettings::dirEditChanged(QString dir)
{
if (!_current) return;
_current->setText(1, dir);
}
bool SourceSettings::check(QString& errorMsg, QString& errorItem)
{
for(int idx=0; idx< ui.dirList->topLevelItemCount(); idx++) {
QTreeWidgetItem* item = ui.dirList->topLevelItem(idx);
QString dir = item->text(1);
if (QDir(dir).exists()) continue;
errorMsg = tr("Directory does not exist");
errorItem = QString("%1").arg(idx+1);
return false;
}
return true;
}
void SourceSettings::accept()
{
GlobalConfig* c = GlobalConfig::config();
QHash<QString, QStringList> dirs;
for(int idx=0; idx< ui.dirList->topLevelItemCount(); idx++) {
QTreeWidgetItem* item = ui.dirList->topLevelItem(idx);
dirs[item->text(0)] << item->text(1);
}
QHash<QString, QStringList>::const_iterator oit = dirs.constBegin();
for(;oit != dirs.constEnd(); ++oit) {
if (oit.key() == _always)
c->setGeneralSourceDirs(oit.value());
else
c->setObjectSourceDirs(oit.key(), oit.value());
}
}
#include "sourcesettings.moc"
/* This file is part of KCachegrind.
Copyright (C) 2009 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
KCachegrind 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, version 2.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/*
* Source annotation directory settings config page
*/
#ifndef SOURCESETTINGS_H
#define SOURCESETTINGS_H
#include "configpage.h"
#include "ui_sourcesettings.h"
class TraceData;
class QTreeWidgetItem;
class SourceSettings: public ConfigPage
{
Q_OBJECT
public:
SourceSettings(TraceData* data, QWidget* parent);
virtual ~SourceSettings() {}
bool check(QString&, QString&);
void accept();
void activate(QString s);
public slots:
void addClicked();
void deleteClicked();
void browseClicked();
void dirListItemChanged(QTreeWidgetItem*, QTreeWidgetItem*);
void objectChanged(QString);
void dirEditChanged(QString);
private:
void update();
Ui::SourceSettings ui;
QTreeWidgetItem* _current;
QString _always;
};
#endif // SOURCESETTINGS_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SourceSettings</class>
<widget class="QWidget" name="SourceSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QTreeWidget" name="dirList">
<column>
<property name="text">
<string>ELF Object</string>
</property>
</column>
<column>
<property name="text">
<string>Base Directory</string>
</property>
</column>
</widget>
</item>
<item row="0" column="2">
<layout class="QVBoxLayout" name="_2">
<item>
<widget class="QPushButton" name="addDirButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteDirButton">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
<item>
<spacer name="Spacer5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16</width>
<height>49</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>ELF Object:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="objectBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Base Directory:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="dirEdit"/>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="browseDirButton">
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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