File indexing completed on 2024-04-14 03:40:11
0001 /************************************************************************************* 0002 * Copyright (C) 2007 by Aleix Pol <aleixpol@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #include "dictionary.h" 0020 #include <analitza/expression.h> 0021 #include <analitza/variables.h> 0022 #include <analitzagui/operatorsmodel.h> 0023 #include <analitzagui/plotsview2d.h> 0024 #include <analitzaplot/functiongraph.h> 0025 #include <analitzaplot/plotsfactory.h> 0026 #include <analitzaplot/plotsmodel.h> 0027 0028 #include <QFormLayout> 0029 #include <QGroupBox> 0030 #include <QLabel> 0031 #include <QVBoxLayout> 0032 #include <klocalizedstring.h> 0033 0034 Dictionary::Dictionary(QWidget *p) 0035 : QWidget(p) 0036 { 0037 m_ops = new OperatorsModel(this); 0038 m_sortProxy = new QSortFilterProxyModel(this); 0039 m_sortProxy->setSourceModel(m_ops); 0040 m_sortProxy->sort(2, Qt::AscendingOrder); 0041 m_sortProxy->setFilterKeyColumn(2); 0042 0043 m_vars = QSharedPointer<Analitza::Variables>(new Analitza::Variables); 0044 0045 QGroupBox *descr = new QGroupBox(i18n("Information"), this); 0046 descr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 0047 QFormLayout *descrLayo = new QFormLayout; 0048 QVBoxLayout *graphLayo = new QVBoxLayout(this); 0049 m_name = new QLabel(descr); 0050 m_descr = new QLabel(descr); 0051 m_sample = new QLabel(descr); 0052 m_example = new QLabel(descr); 0053 m_funcs = new Analitza::PlotsModel(descr); 0054 m_graph = new Analitza::PlotsView2D(descr); 0055 m_graph->setTicksShown(Qt::Orientation(0)); 0056 m_graph->setModel(m_funcs); 0057 m_graph->setReadOnly(true); 0058 m_graph->setViewport(QRect(QPoint(-30, 7), QPoint(30, -7))); 0059 m_graph->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 0060 0061 m_name->setIndent(10); 0062 m_descr->setIndent(10); 0063 m_sample->setIndent(10); 0064 m_example->setIndent(10); 0065 0066 m_example->setTextInteractionFlags(Qt::TextSelectableByMouse); 0067 0068 descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(0, Qt::Horizontal).toString()), m_name); 0069 descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(1, Qt::Horizontal).toString()), m_descr); 0070 descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(2, Qt::Horizontal).toString()), m_sample); 0071 descrLayo->addRow(i18n("<b>%1</b>", m_ops->headerData(3, Qt::Horizontal).toString()), m_example); 0072 descrLayo->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow); 0073 graphLayo->addWidget(descr); 0074 graphLayo->addWidget(m_graph); 0075 descr->setLayout(descrLayo); 0076 0077 m_funcs->clear(); 0078 // connect(m_list, SIGNAL(clicked(QModelIndex)), this, SLOT(activated(QModelIndex))); 0079 } 0080 0081 Dictionary::~Dictionary() 0082 { 0083 } 0084 0085 void Dictionary::activated(const QModelIndex &idx, const QModelIndex &prev) 0086 { 0087 Q_UNUSED(prev); 0088 0089 m_funcs->clear(); 0090 if (idx.isValid()) { 0091 QModelIndex nameIdx, descriptionIdx, sampleIdx, exampleIdx; 0092 nameIdx = idx.sibling(idx.row(), 0); 0093 descriptionIdx = idx.sibling(idx.row(), 1); 0094 sampleIdx = idx.sibling(idx.row(), 2); 0095 exampleIdx = idx.sibling(idx.row(), 3); 0096 0097 QString name = m_sortProxy->data(nameIdx).toString(); 0098 QString description = m_sortProxy->data(descriptionIdx).toString(); 0099 QString sample = m_sortProxy->data(sampleIdx).toString(); 0100 QString example = m_sortProxy->data(exampleIdx).toString(); 0101 0102 Analitza::Expression e(example, false); 0103 0104 m_name->setText(name); 0105 m_descr->setText(description); 0106 m_sample->setText(sample); 0107 m_example->setText(example); 0108 0109 m_funcs->addPlot(Analitza::PlotsFactory::self()->requestPlot(e, Analitza::Dim2D, m_vars).create(QColor(0, 150, 0), QStringLiteral("dict"))); 0110 } else { 0111 m_name->setText(QString()); 0112 m_descr->setText(QString()); 0113 m_sample->setText(QString()); 0114 m_example->setText(QString()); 0115 } 0116 } 0117 0118 void Dictionary::setFilter(const QString &filter) 0119 { 0120 m_sortProxy->setFilterFixedString(filter); 0121 }