-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSupportClasses.cpp
74 lines (63 loc) · 2.4 KB
/
SupportClasses.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
////////////////////////////////////////////////////////////////////////
// Copyright 2009-2018 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2018, NTESS
// All rights reserved.
//
// Portions are copyright of other developers:
// See the file CONTRIBUTORS.TXT in the top level directory
// the distribution for more information.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
////////////////////////////////////////////////////////////////////////
#include "SupportClasses.h"
///////////////////////////////////////////////////////////////////////////////
SpinBoxEditor::SpinBoxEditor(int min, int max, QObject* parent /*=0*/)
: QStyledItemDelegate(parent)
{
// Save off the min and max
m_min = min;
m_max = max;
}
// Create Editor when we construct SpinBoxDelegate
QWidget* SpinBoxEditor::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
Q_UNUSED(option)
Q_UNUSED(index)
// TableView need to create an Editor
// Create Editor when we construct MyDelegate
// and return the Editor
QSpinBox* editor = new QSpinBox(parent);
editor->setMinimum(m_min);
editor->setMaximum(m_max);
return editor;
}
// Then, we set the Editor
void SpinBoxEditor::setEditorData(QWidget* editor, const QModelIndex& index) const
{
// Get the value via index of the Model
int value = index.model()->data(index, Qt::EditRole).toInt();
// Put the value into the SpinBox
QSpinBox* spinbox = static_cast<QSpinBox*>(editor);
spinbox->setValue(value);
}
// When we modify data, this model reflect the change
void SpinBoxEditor::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
{
// When we modify data, this model reflect the change
QSpinBox* spinbox = static_cast<QSpinBox*>(editor);
spinbox->interpretText();
int value = spinbox->value();
model->setData(index, value, Qt::EditRole);
}
// Give the SpinBox the info on size and location
void SpinBoxEditor::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
Q_UNUSED(index)
// Give the SpinBox the info on size and location
editor->setGeometry(option.rect);
}