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

qcachegrind: add currently empty configuration dialog

The config consists currently only of a test config page.

svn path=/trunk/KDE/kdesdk/kcachegrind/; revision=1048527
parent baa4d08d
include_directories(../libcore ../libviews)
set(qcachegrind_SRCS qcgmain.cpp qcgtoplevel.cpp qcgconfig.cpp)
set(qcachegrind_SRCS qcgmain.cpp qcgtoplevel.cpp qcgconfig.cpp
configdialog.cpp configpage.cpp)
qt4_automoc(${qcachegrind_SRCS})
qt4_add_resources(qcachegrind_RSRC qcachegrind.qrc)
......
/* 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.
*/
/*
* QCachegrind configuration dialog
*/
#include "configdialog.h"
#include <QWidget>
#include <QLabel>
#include <QFrame>
#include <QListWidget>
#include <QStackedWidget>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTimer>
//
// ConfigDialog
//
ConfigDialog::ConfigDialog(TraceData* /*data*/, QWidget* parent, QString s)
: QDialog(parent)
{
setWindowTitle(tr("Configure QCachegrind"));
_listWidget = new QListWidget(this);
_listWidget->setMaximumWidth(100);
_widgetStack = new QStackedWidget(this);
_titleLabel = new QLabel(this);
QFont labelFont;
labelFont.setBold(true);
_titleLabel->setFont(labelFont);
_errorLabel = new QLabel(this);
_errorLabel->setIndent(9);
QDialogButtonBox* bbox = new QDialogButtonBox(this);
bbox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
QVBoxLayout* vbox1 = new QVBoxLayout();
vbox1->addWidget(_titleLabel);
QFrame* f1 = new QFrame(this);
f1->setFrameShape(QFrame::HLine);
vbox1->addWidget(f1);
vbox1->addWidget(_errorLabel);
vbox1->addWidget(_widgetStack);
QHBoxLayout* hbox = new QHBoxLayout();
hbox->addWidget(_listWidget);
hbox->addLayout(vbox1);
QVBoxLayout* vbox = new QVBoxLayout(this);
vbox->addLayout(hbox);
QFrame* f2 = new QFrame(this);
f2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
vbox->addWidget(f2);
vbox->addWidget(bbox);
connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
connect(_listWidget, SIGNAL(currentTextChanged(QString)),
this, SLOT(listItemChanged(QString)));
connect(&_clearTimer, SIGNAL(timeout()), this, SLOT(clearError()));
addPage(new ConfigPage(this, "Test", "Test Page"));
activate(s);
}
void ConfigDialog::addPage(ConfigPage* p)
{
_widgetStack->addWidget(p);
_listWidget->addItem(p->title());
_pages.insert(p->title(), p);
}
void ConfigDialog::listItemChanged(QString s)
{
ConfigPage* p = _pages.value(s);
if (!p) return;
_titleLabel->setText(p->longTitle());
_widgetStack->setCurrentWidget(p);
if (!_activeSetting.isEmpty()) {
p->activate(_activeSetting);
_activeSetting.clear();
}
}
void ConfigDialog::clearError()
{
_errorLabel->setText(QString());
}
void ConfigDialog::activate(QString s)
{
if (s.isEmpty())
_listWidget->setCurrentRow(0);
QString page = s;
_activeSetting.clear();
int p = s.indexOf("/");
if (p>0) {
page = s.left(p);
_activeSetting = s.mid(p+1);
}
for(int row=0; row<_listWidget->count(); row++) {
QListWidgetItem* i = _listWidget->item(row);
if (i->text() != page) continue;
if (_listWidget->currentRow() == row)
// even without page change, forward activation
listItemChanged(page);
else
_listWidget->setCurrentRow(row);
}
}
void ConfigDialog::accept()
{
ConfigPage* p;
QString errorMsg, errorItem;
foreach(p, _pages)
if (!p->check(errorMsg, errorItem)) {
if (!errorMsg.isEmpty()) {
errorMsg = QString("<font color=red>%1</color>").arg(errorMsg);
_errorLabel->setText(errorMsg);
_clearTimer.start(5000);
}
activate(QString("%1/%2").arg(p->title(), errorItem));
return;
}
foreach(p, _pages)
p->accept();
QDialog::accept();
}
#include "configdialog.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.
*/
/*
* QCachegrind configuration dialog
*/
#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H
#include <QString>
#include <QDialog>
#include <QMap>
#include <QTimer>
#include "configpage.h"
class QWidget;
class QLabel;
class QListWidget;
class QStackedWidget;
class TraceData;
class ConfigDialog: public QDialog
{
Q_OBJECT
public:
// If s is not empty, navigate to a given setting on opening
ConfigDialog(TraceData* data, QWidget* parent, QString s = QString::null);
void activate(QString);
public slots:
void accept();
void listItemChanged(QString);
void clearError();
private:
void addPage(ConfigPage*);
QLabel* _titleLabel;
QLabel* _errorLabel;
QListWidget *_listWidget;
QStackedWidget *_widgetStack;
QMap<QString,ConfigPage*> _pages;
QString _activeSetting;
QTimer _clearTimer;
};
#endif // CONFIGDIALOG
/* 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.
*/
/*
* Base class of a subpage in the configuration dialog
*/
#include "configpage.h"
#include <QLabel>
#include <QWidget>
//
// ConfigPage
//
ConfigPage::ConfigPage(QWidget* parent, QString title, QString longTitle)
: QWidget(parent)
{
_title = title;
if (longTitle.isEmpty())
_longTitle = title;
else
_longTitle = longTitle;
}
void ConfigPage::activate(QString s)
{
QWidget* w = _names.value(s);
if (w) w->setFocus();
}
bool ConfigPage::check(QString&, QString&)
{
return true;
}
void ConfigPage::accept()
{}
QString ConfigPage::inRangeError(int from, int to)
{
return tr("Value must be between %1 and %2.").arg(from).arg(to);
}
/* 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.
*/
/*
* Base class for pages in configuration dialog
*/
#ifndef CONFIGPAGE_H
#define CONFIGPAGE_H
#include <QString>
#include <QMap>
#include <QWidget>
class ConfigPage: public QWidget
{
public:
ConfigPage(QWidget* parent, QString title, QString longTitle = QString());
virtual ~ConfigPage() {}
QString title() { return _title; }
QString longTitle() { return _longTitle; }
// the default implementation focuses on widget named via <names>
virtual void activate(QString);
// called on OK; prohibits closing by returning false
// an error message to show and item name to navigate to can be set
virtual bool check(QString& errorMsg, QString& errorItem);
virtual void accept();
protected:
QString inRangeError(int, int);
QMap<QString, QWidget*> _names;
private:
QString _title;
QString _longTitle;
};
#endif // CONFIGPAGE
......@@ -28,6 +28,8 @@ QMAKE_EXTRA_COMPILERS = new_moc
# Input
NHEADERS += qcgconfig.h \
qcgtoplevel.h \
configdialog.h \
configpage.h \
../libcore/context.h \
../libcore/costitem.h \
../libcore/subcost.h \
......@@ -73,6 +75,8 @@ NHEADERS += qcgconfig.h \
SOURCES += qcgmain.cpp \
qcgconfig.cpp \
qcgtoplevel.cpp \
configdialog.cpp \
configpage.cpp \
../libcore/context.cpp \
../libcore/costitem.cpp \
../libcore/subcost.cpp \
......
......@@ -52,6 +52,7 @@
#include "globalconfig.h"
#include "multiview.h"
#include "callgraphview.h"
#include "configdialog.h"
QCGTopLevel::QCGTopLevel()
{
......@@ -524,6 +525,11 @@ void QCGTopLevel::createActions()
hint = tr("Go forward in function selection history");
_forwardAction->setToolTip( hint );
// settings menu actions
_configureAction = new QAction(tr("&Configure"), this);
_configureAction->setStatusTip(tr("Configure QCachegrind"));
connect(_configureAction, SIGNAL(triggered()), this, SLOT(configure()));
// help menu actions
_aboutAction = new QAction(tr("&About QCachegrind ..."), this);
_aboutAction->setStatusTip(tr("Show the application's About box"));
......@@ -583,6 +589,8 @@ void QCGTopLevel::createMenu()
QMenu* settingsMenu = mBar->addMenu(tr("&Settings"));
settingsMenu->addAction(_sidebarMenuAction);
settingsMenu->addSeparator();
settingsMenu->addAction(_configureAction);
QMenu* helpMenu = mBar->addMenu(tr("&Help"));
helpMenu->addAction(_aboutAction);
......@@ -631,6 +639,15 @@ void QCGTopLevel::about()
QMessageBox::about(this, tr("About QCachegrind"), text);
}
void QCGTopLevel::configure(QString s)
{
ConfigDialog d(_data, this, s);
if (d.exec() == QDialog::Accepted) {
GlobalConfig::config()->saveOptions();
configChanged();
}
}
void QCGTopLevel::togglePartDock()
{
......
......@@ -96,6 +96,7 @@ public slots:
void reload();
void exportGraph();
void newWindow();
void configure(QString page = QString::null);
void about();
// layouts
......@@ -223,7 +224,7 @@ private:
QAction *_layoutNext, *_layoutPrev, *_layoutRemove, *_layoutDup;
QAction *_layoutRestore, *_layoutSave;
QAction *_upAction, *_forwardAction, *_backAction;
QAction *_aboutAction, *_aboutQtAction;
QAction *_configureAction, *_aboutAction, *_aboutQtAction;
QComboBox* _eventTypeBox;
TraceFunction* _function;
......
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