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

kalgebra

  • sources
  • kde-4.14
  • 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 
35 Dictionary::Dictionary(QWidget *p) : QWidget(p)
36 {
37  m_ops=new OperatorsModel(this);
38  m_sortProxy = new QSortFilterProxyModel(this);
39  m_sortProxy->setSourceModel(m_ops);
40  m_sortProxy->sort(2, Qt::AscendingOrder);
41  m_sortProxy->setFilterKeyColumn(2);
42 
43  m_vars = new Analitza::Variables;
44 
45  QGroupBox *descr=new QGroupBox(i18n("Information"), this);
46  descr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
47  QFormLayout *descrLayo=new QFormLayout;
48  QVBoxLayout *graphLayo=new QVBoxLayout(this);
49  m_name=new QLabel(descr);
50  m_descr=new QLabel(descr);
51  m_sample=new QLabel(descr);
52  m_example=new QLabel(descr);
53  m_funcs=new Analitza::PlotsModel(descr);
54  m_graph=new Analitza::PlotsView2D(descr);
55  m_graph->setTicksShown(0);
56  m_graph->setModel(m_funcs);
57  m_graph->setReadOnly(true);
58  m_graph->setViewport(QRect(QPoint(-30, 7), QPoint(30, -7)));
59  m_graph->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
60 
61  m_name->setIndent(10);
62  m_descr->setIndent(10);
63  m_sample->setIndent(10);
64  m_example->setIndent(10);
65 
66  m_example->setTextInteractionFlags(Qt::TextSelectableByMouse);
67 
68  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(0, Qt::Horizontal).toString()), m_name);
69  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(1, Qt::Horizontal).toString()), m_descr);
70  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(2, Qt::Horizontal).toString()), m_sample);
71  descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(3, Qt::Horizontal).toString()), m_example);
72  descrLayo->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
73  graphLayo->addWidget(descr);
74  graphLayo->addWidget(m_graph);
75  descr->setLayout(descrLayo);
76 
77  m_funcs->clear();
78 // connect(m_list, SIGNAL(clicked(QModelIndex)), this, SLOT(activated(QModelIndex)));
79 }
80 
81 Dictionary::~Dictionary()
82 {
83  delete m_vars;
84 }
85 
86 void Dictionary::activated(const QModelIndex& idx, const QModelIndex& prev)
87 {
88  Q_UNUSED(prev);
89 
90  m_funcs->clear();
91  if(idx.isValid()) {
92  QModelIndex nameIdx, descriptionIdx, sampleIdx, exampleIdx;
93  nameIdx = idx.sibling(idx.row(), 0);
94  descriptionIdx = idx.sibling(idx.row(), 1);
95  sampleIdx = idx.sibling(idx.row(), 2);
96  exampleIdx = idx.sibling(idx.row(), 3);
97 
98  QString name=m_sortProxy->data(nameIdx).toString();
99  QString description=m_sortProxy->data(descriptionIdx).toString();
100  QString sample=m_sortProxy->data(sampleIdx).toString();
101  QString example=m_sortProxy->data(exampleIdx).toString();
102 
103  Analitza::Expression e(example, false);
104 
105  m_name->setText(name);
106  m_descr->setText(description);
107  m_sample->setText(sample);
108  m_example->setText(example);
109 
110  QString error;
111  if(!error.isEmpty())
112  qDebug() << "dict formula error: " << error << e.toMathMLPresentation();
113 
114  m_funcs->addPlot(Analitza::PlotsFactory::self()->requestPlot(e, Analitza::Dim2D, m_vars).create(QColor(0,150,0), "dict"));
115  } else {
116  QString error;
117  m_name->setText(QString());
118  m_descr->setText(QString());
119  m_sample->setText(QString());
120  m_example->setText(QString());
121  }
122 }
123 
124 void Dictionary::setFilter(const QString &filter)
125 {
126  m_sortProxy->setFilterFixedString(filter);
127 }
128 
129 #include "dictionary.moc"
QModelIndex
QWidget
QWidget::create
void create(WId window, bool initializeWindow, bool destroyOldWindow)
QSortFilterProxyModel::sort
virtual void sort(int column, Qt::SortOrder order)
QSortFilterProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
QPoint
Dictionary::setFilter
void setFilter(const QString &)
Definition: dictionary.cpp:124
QFormLayout::setFieldGrowthPolicy
void setFieldGrowthPolicy(FieldGrowthPolicy policy)
QObject::name
const char * name() const
QRect
QModelIndex::isValid
bool isValid() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QWidget::setLayout
void setLayout(QLayout *layout)
QGroupBox
Dictionary::activated
void activated(const QModelIndex &prev, const QModelIndex &)
Definition: dictionary.cpp:86
QString::isEmpty
bool isEmpty() const
QModelIndex::row
int row() const
QVBoxLayout
QLabel::setText
void setText(const QString &)
QString
QColor
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
QFormLayout::addRow
void addRow(QWidget *label, QWidget *field)
QSortFilterProxyModel
QLabel::setTextInteractionFlags
void setTextInteractionFlags(QFlags< Qt::TextInteractionFlag > flags)
QModelIndex::sibling
QModelIndex sibling(int row, int column) const
QSortFilterProxyModel::setFilterFixedString
void setFilterFixedString(const QString &pattern)
Dictionary::~Dictionary
virtual ~Dictionary()
Definition: dictionary.cpp:81
QLabel::setIndent
void setIndent(int)
QLabel
QVariant::toString
QString toString() const
QSortFilterProxyModel::setFilterKeyColumn
void setFilterKeyColumn(int column)
QSortFilterProxyModel::data
virtual QVariant data(const QModelIndex &index, int role) const
dictionary.h
QFormLayout
Dictionary::Dictionary
Dictionary(QWidget *p=0)
Definition: dictionary.cpp:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:11:49 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
  • 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