annotate gui/src/HistoryDockWidget.cpp @ 13506:c70511cf64ee

Reformatted to GNU Style.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Sun, 17 Jul 2011 22:59:28 +0200
parents 13e3d60aff2d
children 86adc9c4ec4b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13504
13e3d60aff2d Replaced Quint with OctaveGUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13495
diff changeset
1 /* OctaveGUI - A graphical user interface for Octave
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
2 * Copyright (C) 2011 Jacob Dawid
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
3 * jacob.dawid@googlemail.com
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
4 *
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
8 * (at your option) any later version.
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
9 *
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
14 *
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
17 */
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
18
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
19 #include "HistoryDockWidget.h"
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
20 #include <QHBoxLayout>
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
21
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
22 HistoryDockWidget::HistoryDockWidget (QWidget * parent):QDockWidget (parent)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
23 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
24 setObjectName ("HistoryDockWidget");
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
25 construct ();
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
26 }
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
27
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
28 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
29 HistoryDockWidget::handleListViewItemDoubleClicked (QModelIndex modelIndex)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
30 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
31 QString command = m_historyListModel->data (modelIndex, 0).toString ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
32 emit commandDoubleClicked (command);
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
33 }
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
34
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
35 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
36 HistoryDockWidget::construct ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
37 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
38 m_historyListModel = new QStringListModel ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
39 m_historyListView = new QListView (this);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
40 m_historyListView->setModel (m_historyListModel);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
41 m_historyListView->setAlternatingRowColors (true);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
42 m_historyListView->setEditTriggers (QAbstractItemView::NoEditTriggers);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
43 QHBoxLayout *layout = new QHBoxLayout ();
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
44
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
45 setWindowTitle (tr ("Command History"));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
46 setWidget (new QWidget ());
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
47
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
48 layout->addWidget (m_historyListView);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
49 layout->setMargin (2);
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
50
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
51 widget ()->setLayout (layout);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
52 connect (m_historyListView, SIGNAL (doubleClicked (QModelIndex)), this,
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
53 SLOT (handleListViewItemDoubleClicked (QModelIndex)));
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
54 }
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
55
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
56 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
57 HistoryDockWidget::updateHistory (string_vector historyEntries)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
58 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
59 QStringList stringList = m_historyListModel->stringList ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
60 for (int i = 0; i < historyEntries.length (); i++)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
61 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
62 QString command (historyEntries[i].c_str ());
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
63 if (!command.startsWith ("#"))
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
64 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
65 stringList.push_front (command);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
66 }
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
67 }
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
68 m_historyListModel->setStringList (stringList);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
69 emit information (tr ("History updated."));
13495
11e03a76d8c0 Added source files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
70 }