[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/utils/abakus/src
From:       Michael Pyne <michael.pyne () kdemail ! net>
Date:       2007-12-22 0:58:09
Message-ID: 1198285089.224343.16699.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 751504 by mpyne:

Remove one major usage of QTreeWidget in abakus.
Remove stray scons-build file.
some cleanups.


 M  +1 -2      CMakeLists.txt  
 D             SConscript  
 M  +17 -1     abakuslistview.cpp  
 M  +9 -1      abakuslistview.h  
 M  +48 -57    mainwindow.cpp  
 M  +8 -7      mainwindow.h  
 D             resultlistview.cpp  
 D             resultlistview.h  
 D             resultlistviewtext.cpp  
 D             resultlistviewtext.h  
 A             resultmodel.cpp   [License: GPL (v2+) (wrong address)]
 A             resultmodel.h   [License: GPL (v2+) (wrong address)]


--- trunk/playground/utils/abakus/src/CMakeLists.txt #751503:751504
@@ -115,8 +115,7 @@
     numerictypes.cpp
     ${CMAKE_CURRENT_BINARY_DIR}/parser_yacc.cpp
     result.cpp
-    resultlistview.cpp
-    resultlistviewtext.cpp
+    resultmodel.cpp
     rpnmuncher.cpp
     valuemanager.cpp
     #    dcopIface.skel
--- trunk/playground/utils/abakus/src/abakuslistview.cpp #751503:751504
@@ -1,6 +1,6 @@
 /*
  * abakuslistview.cpp - part of abakus
- * Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
+ * Copyright (C) 2004, 2005, 2007 Michael Pyne <michael.pyne@kdemail.net>
  *
  * 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
@@ -23,6 +23,7 @@
 #include <QtGui/QMenu>
 #include <QtGui/QAction>
 #include <QtGui/QTreeWidgetItem>
+#include <QtGui/QTreeWidgetItemIterator>
 #include <QtCore/QList>
 //#include <qdragobject.h>
 //#include <qheader.h>
@@ -43,6 +44,21 @@
                   SLOT(slotItemClicked(QTreeWidgetItem *)));
 }
 
+void ListView::redrawItems()
+{
+    QTreeWidgetItemIterator it(this);
+
+    while(*it) {
+        ValueTreeWidgetItem *item = dynamic_cast<ValueTreeWidgetItem *>(*it);
+        ++it;
+
+        if(!item)
+            continue;
+
+        item->valueChanged();
+    }
+}
+
 #if 0
 QDragObject *ListView::dragObject()
 {
--- trunk/playground/utils/abakus/src/abakuslistview.h #751503:751504
@@ -2,7 +2,7 @@
 #define ABAKUS_LISTVIEW_H
 /*
  * abakuslistview.h - part of abakus
- * Copyright (C) 2004, 2005 Michael Pyne <michael.pyne@kdemail.net>
+ * Copyright (C) 2004, 2005, 2007 Michael Pyne <michael.pyne@kdemail.net>
  *
  * 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
@@ -33,6 +33,14 @@
     public:
     ListView(QWidget *parent);
 
+    public slots:
+    /**
+     * Causes all items to be redrawn.  Should be used for when the precision of a \
value +     * changes for example, or other actions that would cause the display of \
all items +     * to become inaccurate.
+     */
+    void redrawItems();
+
     protected:
 //    virtual QDragObject *dragObject();
 
--- trunk/playground/utils/abakus/src/mainwindow.cpp #751503:751504
@@ -34,24 +34,18 @@
 #include <kvbox.h>
 #include <khbox.h>
 
-#include <qlayout.h>
-#include <qradiobutton.h>
-#include <qbuttongroup.h>
-#include <qsplitter.h>
-#include <QtGui/QLineEdit>
-#include <QtGui/QContextMenuEvent>
+#include <QtGui>
 
 #include "editor.h"
 #include "evaluator.h"
 #include "function.h"
-#include "resultlistview.h"
-#include "resultlistviewtext.h"
 #include "valuemanager.h"
 #include "node.h"
 #include "rpnmuncher.h"
 //#include "dcopIface.h"
 #include "abakuslistview.h"
 #include "result.h"
+#include "resultmodel.h"
 
 MainWindow::MainWindow() : KXmlGuiWindow(0), m_popup(0), m_insert(false)
 {
@@ -62,7 +56,7 @@
     QVBoxLayout *layout = new QVBoxLayout(box);
     m_layout = layout;
     layout->setSpacing(6);
-    layout->setMargin(6);
+    layout->setMargin(0);
 
     QWidget *configBox = new QWidget(box);
     layout->addWidget(configBox);
@@ -99,15 +93,20 @@
     m_history->setSpacing(6);
     m_history->setMargin(0);
 
-    m_result = new ResultListView(m_history);
-    m_result->setSelectionMode(ResultListView::NoSelection);
-    m_result->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-    connect(m_result, SIGNAL(signalEntrySelected(const QString &)),
-                      SLOT(slotEntrySelected(const QString &)));
-    connect(m_result, SIGNAL(signalResultSelected(const QString &)),
-                      SLOT(slotResultSelected(const QString &)));
+    m_resultItemModel = new ResultModel(this);
+    QTreeView *resultList = new QTreeView(m_history);
+    resultList->setSelectionMode(QTreeView::NoSelection);
+    resultList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    resultList->setModel(m_resultItemModel->model());
+    resultList->header()->setResizeMode(QHeaderView::ResizeToContents);
+    resultList->setAlternatingRowColors(true);
+    resultList->setRootIsDecorated(false);
+    connect(m_resultItemModel, SIGNAL(signalColumnChanged(int)),
+            resultList, SLOT(resizeColumnToContents(int)));
+    connect(resultList,  SIGNAL(clicked(const QModelIndex &)),
+            this, SLOT(itemClicked(const QModelIndex &)));
 
-    m_history->setStretchFactor(m_result, 1);
+    m_history->setStretchFactor(resultList, 1);
     layout->setStretchFactor(m_history, 1);
 
     KHBox *editBox = new KHBox(box);
@@ -123,7 +122,8 @@
     connect(evalButton, SIGNAL(clicked()), SLOT(slotEvaluate()));
 
     connect(m_edit, SIGNAL(returnPressed()), SLOT(slotReturnPressed()));
-    connect(m_edit, SIGNAL(textChanged()), SLOT(slotTextChanged()));
+    connect(m_edit, SIGNAL(textChanged(const QString &)),
+            this,   SLOT(slotTextChanged(const QString &)));
 
     m_listSplitter = new QSplitter(Qt::Vertical, m_mainSplitter);
     m_fnList = new FunctionListView(m_listSplitter);
@@ -183,22 +183,20 @@
     QString text = m_edit->text();
 
     text.replace("\n", "");
+    if(text.isEmpty())
+        return;
 
     // TODO: Put this back in, used to be Editor.
     // m_edit->appendHistory(text);
 
-    // Item to insert after
-    ResultListViewText *after = m_result->lastItem();
-
     // Expand $foo references.
-    QString str = interpolateExpression(text, after);
+    QString str = interpolateExpression(text);
 
-    QString resultVal;
-    ResultListViewText *item;
-
-    if(str.isNull())
+    if(str.isEmpty())
         return; // Error already has been posted
 
+    QString resultVal;
+
     m_insert = false; // Assume we failed
 
     if(inRPNMode()) {
@@ -223,7 +221,7 @@
             return;
         }
 
-        item = new ResultListViewText(m_result, str, resultVal, after, false);
+        m_resultItemModel->addResult(str, result);
     }
     else {
 
@@ -246,22 +244,19 @@
                 resultVal = result.toString();
 
                 ValueManager::instance()->setValue("ans", result);
-                if(!compact)
-                    item = new ResultListViewText(m_result, str, result, after, \
false);  
+                m_resultItemModel->addResult(str, result);
                 m_insert = true;
             break;
 
             case Result::Null: // OK, no result to speak of
                 resultVal = "OK";
-                if(!compact)
-                    item = new ResultListViewText(m_result, str, resultVal, after, \
true); +                m_resultItemModel->addMessage(resultVal);
             break;
 
             default:
                 resultVal = Result::lastResult()->message();
-                if(!compact)
-                    item = new ResultListViewText(m_result, str, resultVal, after, \
true); +                m_resultItemModel->addMessage(resultVal);
         }
 
         // Skip creating list view items if in compact mode.
@@ -275,16 +270,11 @@
 
     m_edit->setText(text);
 
-    m_result->setCurrentItem(item);
-    m_result->scrollToItem(item);
-
     QTimer::singleShot(0, m_edit, SLOT(selectAll()));
 }
 
-void MainWindow::slotTextChanged()
+void MainWindow::slotTextChanged(const QString &str)
 {
-    QString str = m_edit->text();
-
     if(str.length() == 1 && m_insert) {
         m_insert = false;
 
@@ -567,7 +557,7 @@
     ta->setText(i18n("C&ustom Precision..."));
     ta->setActionGroup(precisionGroup);
 
-    QAction *a = ac->addAction("clearHistory", m_result, SLOT(clear()));
+    QAction *a = ac->addAction("clearHistory", m_resultItemModel, SLOT(clear()));
     a->setText(i18n("Clear &History"));
     a->setIcon(KIcon("editclear"));
     ta->setShortcut(Qt::SHIFT + Qt::ALT + Qt::Key_L);
@@ -728,7 +718,7 @@
 {
 }
 
-QString MainWindow::interpolateExpression(const QString &text, ResultListViewText \
*after) +QString MainWindow::interpolateExpression(const QString &text)
 {
     QString str(text);
     QRegExp stackRE("\\$\\d+");
@@ -739,9 +729,9 @@
         Abakus::number_t value;
         unsigned numPos = stackStr.mid(1).toUInt();
 
-        if(!m_result->getStackValue(numPos, value)) {
-            new ResultListViewText(m_result, text, i18n("Marker %1 isn't \
                set").arg(stackStr), after, true);
-            return QString::null;
+        if(!m_resultItemModel->stackValue(numPos, value)) {
+            m_resultItemModel->addMessage(i18n("Marker %1 isn't set", stackStr));
+            return QString();
         }
 
         str.replace(pos, stackStr.length(), value.toString());
@@ -796,20 +786,9 @@
 
 void MainWindow::redrawResults()
 {
-    QTreeWidgetItemIterator it(m_result);
+    m_resultItemModel->slotRedrawItems();
+    m_varList->redrawItems();
 
-    while(*it) {
-        static_cast<ResultListViewText *>(*it)->precisionChanged();
-        ++it;
-    }
-
-    it = QTreeWidgetItemIterator(m_varList);
-
-    while(*it) {
-        static_cast<ValueTreeWidgetItem *>(*it)->valueChanged();
-        ++it;
-    }
-
     // Because of the way we implemented the menu, it is possible to deselect
     // every possibility, so make sure we have at least one selected.
     selectCorrectPrecisionAction();
@@ -846,6 +825,18 @@
     }
 }
 
+void MainWindow::itemClicked(const QModelIndex &index)
+{
+    QStandardItem *item = m_resultItemModel->model()->itemFromIndex(index);
+    if(!item)
+        return;
+
+    if(item->column() == 0)
+        slotEntrySelected(item->text());
+    else if(item->column() == 1)
+        slotResultSelected(item->text());
+}
+
 #include "mainwindow.moc"
 
 // vim: set et ts=8 sw=4:
--- trunk/playground/utils/abakus/src/mainwindow.h #751503:751504
@@ -32,15 +32,15 @@
 class QSplitter;
 class QTimer;
 class QMenu;
-class QTreeWidget;
+class QModelIndex;
 class QAction;
 
 //class KComboBox;
 //class Editor;
 class KVBox;
 
-class ResultListView;
-class ResultListViewText;
+class ResultModel;
+class ListView;
 
 class AbakusIface;
 
@@ -59,7 +59,7 @@
 
     private slots:
     void slotReturnPressed();
-    void slotTextChanged();
+    void slotTextChanged(const QString &);
     void slotEvaluate();
 
     void slotPrecisionAuto();
@@ -74,6 +74,7 @@
     void slotDegrees();
     void slotRadians();
 
+    void itemClicked(const QModelIndex &);
     void slotEntrySelected(const QString &text);
     void slotResultSelected(const QString &text);
 
@@ -101,7 +102,7 @@
     void saveConfig();
     void setupLayout();
     void populateListViews();
-    QString interpolateExpression(const QString &text, ResultListViewText *after);
+    QString interpolateExpression(const QString &text);
 
     // Donated via JuK
     QAction *action(const char *key) const;
@@ -117,10 +118,10 @@
     QRadioButton *m_radians;
     QLineEdit *m_edit;
     QMenu *m_popup;
-    ResultListView *m_result;
+    ResultModel *m_resultItemModel;
     QString m_lastError;
     QBoxLayout *m_layout;
-    QTreeWidget *m_fnList, *m_varList;
+    ListView *m_fnList, *m_varList;
     QSplitter *m_mainSplitter, *m_listSplitter;
     QSize m_newSize, m_oldSize;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic