• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kalgebra

  • sources
  • kde-4.12
  • kdeedu
  • kalgebra
  • src
dictionary.cpp
Go to the documentation of this file.
1 /*************************************************************************************
2  * Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org> *
3  * *
4  * This program is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public License *
6  * as published by the Free Software Foundation; either version 2 *
7  * of the License, or (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the Free Software *
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
17  *************************************************************************************/
18 
19 #include "dictionary.h"
20 #include <analitza/variables.h>
21 #include <analitza/expression.h>
22 #include <analitzagui/operatorsmodel.h>
23 #include <analitzagui/plotsview2d.h>
24 #include <analitzaplot/plotsmodel.h>
25 #include <analitzaplot/plotsfactory.h>
26 #include <analitzaplot/functiongraph.h>
27 
28 #include <QLabel>
29 #include <QGroupBox>
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
32 #include <QFormLayout>
33 #include <KLocale>
34 #include <QtMmlWidget>
35 
36 Dictionary::Dictionary(QWidget *p) : QWidget(p)
37 {
38  m_ops=new OperatorsModel(this);
39  m_sortProxy = new QSortFilterProxyModel(this);
40  m_sortProxy->setSourceModel(m_ops);
41  m_sortProxy->sort(2, Qt::AscendingOrder);
42  m_sortProxy->setFilterKeyColumn(2);
43 
44  m_vars = new Analitza::Variables;
45 
46  QGroupBox *descr=new QGroupBox(i18n("Information"), this);
47  descr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
48  QFormLayout *descrLayo=new QFormLayout;
49  QVBoxLayout *graphLayo=new QVBoxLayout(this);
50  m_name=new QLabel(descr);
51  m_descr=new QLabel(descr);
52  m_sample=new QLabel(descr);
53  m_example=new QLabel(descr);
54  m_formula=new QtMmlWidget(descr);
55 // m_formula->setFrameStyle(2);
56  m_formula->setBaseFontPointSize(10);
57  m_formula->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
58  m_funcs=new Analitza::PlotsModel(descr);
59  m_graph=new Analitza::PlotsView2D(descr);
60  m_graph->setTicksShown(0);
61  m_graph->setModel(m_funcs);
62  m_graph->setReadOnly(true);
63  m_graph->setViewport(QRect(QPoint(-30, 7), QPoint(30, -7)));
64  m_graph->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
65 
66  m_name->setIndent(10);
67  m_descr->setIndent(10);
68  m_sample->setIndent(10);
69  m_example->setIndent(10);
70 
71  m_example->setTextInteractionFlags(Qt::TextSelectableByMouse);
72 
73  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(0, Qt::Horizontal).toString()), m_name);
74  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(1, Qt::Horizontal).toString()), m_descr);
75  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(2, Qt::Horizontal).toString()), m_sample);
76  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(3, Qt::Horizontal).toString()), m_example);
77  descrLayo->addRow(i18n("<b>Formula</b>"), m_formula);
78  descrLayo->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
79  graphLayo->addWidget(descr);
80 // graphLayo->addWidget(m_formula);
81  graphLayo->addWidget(m_graph);
82  descr->setLayout(descrLayo);
83 
84  m_funcs->clear();
85  m_formula->setContent("<math />");
86 // connect(m_list, SIGNAL(clicked(QModelIndex)), this, SLOT(activated(QModelIndex)));
87 }
88 
89 Dictionary::~Dictionary()
90 {
91  delete m_vars;
92 }
93 
94 void Dictionary::activated(const QModelIndex& idx, const QModelIndex& prev)
95 {
96  Q_UNUSED(prev);
97 
98  m_funcs->clear();
99  if(idx.isValid()) {
100  QModelIndex nameIdx, descriptionIdx, sampleIdx, exampleIdx;
101  nameIdx = idx.sibling(idx.row(), 0);
102  descriptionIdx = idx.sibling(idx.row(), 1);
103  sampleIdx = idx.sibling(idx.row(), 2);
104  exampleIdx = idx.sibling(idx.row(), 3);
105 
106  QString name=m_sortProxy->data(nameIdx).toString();
107  QString description=m_sortProxy->data(descriptionIdx).toString();
108  QString sample=m_sortProxy->data(sampleIdx).toString();
109  QString example=m_sortProxy->data(exampleIdx).toString();
110 
111  Analitza::Expression e(example, false);
112 
113  m_name->setText(name);
114  m_descr->setText(description);
115  m_sample->setText(sample);
116  m_example->setText(example);
117 
118  QString error;
119  m_formula->setContent(e.toMathMLPresentation(), &error);
120  if(!error.isEmpty())
121  qDebug() << "dict formula error: " << error << e.toMathMLPresentation();
122 
123  m_funcs->addPlot(Analitza::PlotsFactory::self()->requestPlot(e, Analitza::Dim2D, m_vars).create(QColor(0,150,0), "dict"));
124  } else {
125  QString error;
126  m_name->setText(QString());
127  m_descr->setText(QString());
128  m_sample->setText(QString());
129  m_example->setText(QString());
130  m_formula->setContent("<math />", &error);
131  }
132 }
133 
134 void Dictionary::setFilter(const QString &filter)
135 {
136  m_sortProxy->setFilterFixedString(filter);
137 }
138 
139 #include "dictionary.moc"
QWidget
Dictionary::setFilter
void setFilter(const QString &)
Definition: dictionary.cpp:134
Dictionary::activated
void activated(const QModelIndex &prev, const QModelIndex &)
Definition: dictionary.cpp:94
Dictionary::~Dictionary
virtual ~Dictionary()
Definition: dictionary.cpp:89
dictionary.h
Dictionary::Dictionary
Dictionary(QWidget *p=0)
Definition: dictionary.cpp:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalgebra

Skip menu "kalgebra"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal