"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/rootdlg.cpp" between
kpl-4.1.tar.gz and kpl-5.0.tar.gz

About: Kpl is a KDE program for two- and three-dimensional graphical presentation (plots) of data sets and functions. Multidimensional nonlinear parameter and general linear least square parameter fits can be performed.

rootdlg.cpp  (kpl-4.1):rootdlg.cpp  (kpl-5.0)
/*************************************************************************** /***************************************************************************
rootdlg.cpp - description rootdlg.cpp - description
------------------- -------------------
begin : Sam Jan 25 2003 begin : Sam Jan 25 2003
copyright : (C) 2015 by Werner Stille copyright : (C) 2017 by Werner Stille
email : stille@uni-freiburg.de email : kpl@werner-stille.de
***************************************************************************/ ***************************************************************************/
/*************************************************************************** /***************************************************************************
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
***************************************************************************/ ***************************************************************************/
#include <QComboBox> #include <QComboBox>
#include <QDesktopServices>
#include <QDialogButtonBox>
#include <QFile> #include <QFile>
#include <QHeaderView> #include <QHeaderView>
#include <QKeyEvent>
#include <QLabel> #include <QLabel>
#include <QLayout> #include <QLayout>
#include <QPushButton> #include <QPushButton>
#include <QTableWidget> #include <QTableWidget>
#include <QTextStream> #include <QTextStream>
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox> #include <KMessageBox>
#include "doubleedit.h" #include "doubleedit.h"
#include "kpl.h" #include "kpl.h"
#include "kpldoc.h" #include "kpldoc.h"
#include "kplsettings.h" #include "kplsettings.h"
#include "movejob.h" #include "kplutils.h"
#include "rootdlg.h" #include "rootdlg.h"
#include "splineitem.h" #include "splineitem.h"
#include "utils.h"
RootDlg::RootDlg(QWidget* parent, KplDoc* model, const SplineItem* spl0) : RootDlg::RootDlg(QWidget* parent, KplDoc* model, const SplineItem* spl0) :
KDialog(parent), m(model), spl(spl0) QDialog(parent), m(model), spl(spl0)
{ {
setCaption(i18n("Roots")); setWindowTitle(i18n("Roots"));
setButtons(Help | Close | User1); QVBoxLayout* vbox = new QVBoxLayout(this);
setButtonText(User1, i18n("&Export"));
setButtonFocus(Close);
QWidget* page = new QWidget;
setMainWidget(page);
QVBoxLayout* vbox = new QVBoxLayout(page);
vbox->setSpacing(spacingHint());
QHBoxLayout* hbox = new QHBoxLayout; QHBoxLayout* hbox = new QHBoxLayout;
vbox->addLayout(hbox); vbox->addLayout(hbox);
hbox->addWidget(new QLabel(i18n("Condition"))); hbox->addWidget(new QLabel(i18n("Condition")));
hbox->addWidget(eCond = new QComboBox); hbox->addWidget(eCond = new QComboBox);
eCond->addItems(QStringList() << "y(x) - c = 0" << "y'(x) - c = 0" eCond->addItems(QStringList() << "y(x) - c = 0" << "y'(x) - c = 0"
<< "y\"(x) - c = 0" << i18n("Minimum") << "y\"(x) - c = 0" << i18n("Minimum")
<< i18n("Maximum")); << i18n("Maximum"));
connect(eCond, SIGNAL(activated(int)), SLOT(findRoots())); connect(eCond, SIGNAL(activated(int)), SLOT(findRoots()));
hbox->addItem(new QSpacerItem(20, 10, QSizePolicy::MinimumExpanding)); hbox->addItem(new QSpacerItem(20, 10, QSizePolicy::MinimumExpanding));
hbox->addWidget(new QLabel("c")); hbox->addWidget(new QLabel("c"));
skipping to change at line 69 skipping to change at line 67
hbox->addWidget(eOff = new DoubleEdit(0, format, prec)); hbox->addWidget(eOff = new DoubleEdit(0, format, prec));
eOff->setMinimumWidth(eOff->fontMetrics().width(QString::number(-1e-123 / 3, eOff->setMinimumWidth(eOff->fontMetrics().width(QString::number(-1e-123 / 3,
format, format,
prec)) + 3); prec)) + 3);
hbox->addWidget(update = new QPushButton(i18n("&Update"))); hbox->addWidget(update = new QPushButton(i18n("&Update")));
connect(update, SIGNAL(clicked()), SLOT(findRoots())); connect(update, SIGNAL(clicked()), SLOT(findRoots()));
vbox->addWidget(table = new QTableWidget(0, 4)); vbox->addWidget(table = new QTableWidget(0, 4));
table->setHorizontalHeaderLabels(QStringList() << "x" << "y(x)" << "y'(x)" table->setHorizontalHeaderLabels(QStringList() << "x" << "y(x)" << "y'(x)"
<< "y\"(x)"); << "y\"(x)");
table->setMinimumHeight(100); table->setMinimumHeight(100);
setHelp("SEC-ROOTS"); vbox->addWidget(buttonBox = new QDialogButtonBox(QDialogButtonBox::Help |
QDialogButtonBox::Close));
buttonBox->addButton(bExport = new QPushButton(i18n("&Export")),
QDialogButtonBox::ActionRole);
connect(bExport, SIGNAL(clicked()), SLOT(slotExport()));
connect(buttonBox->button(QDialogButtonBox::Help), SIGNAL(clicked()),
SLOT(slotHelp()));
buttonBox->button(QDialogButtonBox::Close)->setFocus();
connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
findRoots(); findRoots();
} }
RootDlg::~RootDlg() RootDlg::~RootDlg()
{ {
} }
void RootDlg::keyPressEvent(QKeyEvent* e)
{
if ((e->QInputEvent::modifiers() == Qt::NoModifier) &&
(e->key() == Qt::Key_F1)) {
buttonBox->button(QDialogButtonBox::Help)->animateClick();
e->accept();
} else
QDialog::keyPressEvent(e);
}
void RootDlg::findRoots() void RootDlg::findRoots()
{ {
QVector<double> zero; QVector<double> zero;
int cond = eCond->currentIndex(); int cond = eCond->currentIndex();
bool extrema = (cond > 2); bool extrema = (cond > 2);
update->setDisabled(extrema); update->setDisabled(extrema);
spl->roots(zero, extrema ? 1 : cond, extrema ? 0 : eOff->value()); spl->roots(zero, extrema ? 1 : cond, extrema ? 0 : eOff->value());
int nz = zero.count(); int nz = zero.count();
int count = 0; int count = 0;
if (nz) { if (nz) {
skipping to change at line 128 skipping to change at line 144
} }
} }
table->setRowCount(count); table->setRowCount(count);
table->resizeColumnsToContents(); table->resizeColumnsToContents();
int w = 0; int w = 0;
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
w = qMax(w, table->columnWidth(i)); w = qMax(w, table->columnWidth(i));
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
table->setColumnWidth(i, w); table->setColumnWidth(i, w);
table->horizontalHeader()->setStretchLastSection(true); table->horizontalHeader()->setStretchLastSection(true);
enableButton(User1, count); bExport->setEnabled(count);
} }
void RootDlg::slotButtonClicked(int button) void RootDlg::slotExport()
{ {
switch (button) { QUrl url;
case User1: { if (KplUtils::getWriteUrl(this, url, KplSettings::currentDir())) {
KUrl url; QFile f(url.isLocalFile() ? url.path() : Utils::tempFileName());
if (Kpl::getWriteUrl(this, url, QString(), "*.dat\n*")) { bool success = f.open(QIODevice::WriteOnly);
QFile f(url.isLocalFile() ? url.path() : KplItem::tempFileName()); if (success) {
if (f.open(QIODevice::WriteOnly)) { QTextStream ts(&f);
QTextStream ts(&f); for (int i = 0; i < table->rowCount(); ++i)
for (int i = 0; i < table->rowCount(); ++i) for (int j = 0; j < 4; ++j)
for (int j = 0; j < 4; ++j) ts << table->item(i, j)->text()
ts << table->item(i, j)->text() << ((j == 3) ? QString("\n") : QString(m->separator()));
<< ((j == 3) ? QString("\n") : QString(m->separator())); f.close();
f.close(); if (!url.isLocalFile())
m->setCurrentDir(url); success = Utils::move(f.fileName(), url, this);
if (!url.isLocalFile()) if (success)
new MoveJob(f.fileName(), url); KplUtils::setCurrentDir(url);
} else
KMessageBox::error(this, i18n("while trying to open"));
}
break;
} }
default: if (!success)
KDialog::slotButtonClicked(button); KMessageBox::error(this, i18n("while trying to open"));
} }
} }
void RootDlg::slotHelp()
{
QDesktopServices::openUrl(QUrl(QStringLiteral("help:/kpl/roots.html")));
}
 End of changes. 14 change blocks. 
36 lines changed or deleted 48 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS