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