• 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
  • mobile
kalgebramobile.cpp
Go to the documentation of this file.
1 /*************************************************************************************
2  * Copyright (C) 2010 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 "kalgebramobile.h"
20 
21 #include <analitzaplot/plotsmodel.h>
22 #include <analitza/variables.h>
23 #include <analitza/expression.h>
24 
25 #include <qdeclarative.h>
26 #include "pluginsmodel.h"
27 
28 using namespace Analitza;
29 
30 KAlgebraMobile* KAlgebraMobile::s_self=0;
31 KAlgebraMobile* KAlgebraMobile::self() { return s_self; }
32 
33 KAlgebraMobile::KAlgebraMobile(QObject* parent)
34  : QObject(parent), m_functionsModel(0), m_vars(new Analitza::Variables)
35 {
36  Q_ASSERT(s_self==0);
37  s_self=this;
38 
39  qmlRegisterType<PluginsModel>("org.kde.kalgebra.mobile", 1, 0, "PluginsModel");
40  qmlRegisterType<QAbstractItemModel>();
41 }
42 
43 PlotsModel* KAlgebraMobile::functionsModel()
44 {
45  if(!m_functionsModel) {
46  m_functionsModel = new Analitza::PlotsModel(this);
47  connect(m_functionsModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(functionRemoved(QModelIndex,int,int)));
48  connect(m_functionsModel, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(functionInserted(QModelIndex,int,int)));
49  connect(m_functionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(functionModified(QModelIndex, QModelIndex)));
50  }
51 
52  return m_functionsModel;
53 }
54 
55 void KAlgebraMobile::functionInserted(const QModelIndex& parent, int start, int end)
56 {
57  Q_ASSERT(!parent.isValid());
58  for(int i=start; i<=end; i++) {
59  QModelIndex idx = functionsModel()->index(i, 1);
60  m_vars->modify(idx.sibling(i,0).data().toString(), Analitza::Expression(idx.data().toString()));
61  }
62 }
63 
64 void KAlgebraMobile::functionRemoved(const QModelIndex& parent, int start, int end)
65 {
66  Q_ASSERT(!parent.isValid());
67  for(int i=start; i<=end; i++) {
68  QModelIndex idx = functionsModel()->index(i);
69  m_vars->remove(functionsModel()->data(idx, Qt::DisplayRole).toString());
70  }
71 }
72 
73 void KAlgebraMobile::functionModified(const QModelIndex& idxA, const QModelIndex& idxB)
74 {
75  if(idxB.column()==1) {
76  for(int i=idxA.row(); i<idxB.row(); ++i) {
77  QModelIndex idx = functionsModel()->index(i, 1);
78  m_vars->modify(idx.sibling(i,0).data().toString(), Analitza::Expression(idx.data().toString()));
79  }
80  } //else TODO: figure out how to control a "rename"
81 }
82 
83 Analitza::Variables* KAlgebraMobile::variables() const { return m_vars; }
QModelIndex
KAlgebraMobile::self
static KAlgebraMobile * self()
Definition: kalgebramobile.cpp:31
KAlgebraMobile::functionsModel
Analitza::PlotsModel * functionsModel()
Definition: kalgebramobile.cpp:43
QModelIndex::isValid
bool isValid() const
KAlgebraMobile::variables
Analitza::Variables * variables() const
QObject
QModelIndex::row
int row() const
pluginsmodel.h
QTest::toString
char * toString(const T &value)
QModelIndex::data
QVariant data(int role) const
QModelIndex::sibling
QModelIndex sibling(int row, int column) const
QModelIndex::column
int column() const
kalgebramobile.h
KAlgebraMobile::KAlgebraMobile
KAlgebraMobile(QObject *parent=0)
Definition: kalgebramobile.cpp:33
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QVariant::toString
QString toString() const
KAlgebraMobile
Definition: kalgebramobile.h:31
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