-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtpy_taskdelegate.cpp
More file actions
55 lines (43 loc) · 1.41 KB
/
gtpy_taskdelegate.cpp
File metadata and controls
55 lines (43 loc) · 1.41 KB
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
/* GTlab - Gas Turbine laboratory
* Source File: gtpy_taskdelegate.cpp
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
*
* Created on: 12.08.2019
* Author: Marvin Noethen (DLR AT-TWK)
*/
#include <QLineEdit>
#include "gt_globals.h"
#include "gt_regexp.h"
#include "gtpy_taskdelegate.h"
GtpyTaskDelegate::GtpyTaskDelegate(QObject* parent) :
QStyledItemDelegate(parent)
{
}
QWidget*
GtpyTaskDelegate::createEditor(QWidget* parent,
const QStyleOptionViewItem& /*option*/,
const QModelIndex& /*index*/) const
{
QLineEdit* lineEdit = new QLineEdit(parent);
#if GT_VERSION < 0x020000
QRegExp onlyLettersAndNumbersAndSpaceExp = GtRegExp::onlyLettersAndNumbersAndSpace();
#else
static QRegularExpression onlyLettersAndNumbersAndSpaceExp("[A-Za-z0-9\\_\\-\\[\\]\\s\\␣]+");
#endif
QValidator* validator = new QRegularExpressionValidator(onlyLettersAndNumbersAndSpaceExp, this->parent());;
lineEdit->setValidator(validator);
return lineEdit;
}
void GtpyTaskDelegate::setEditorData(QWidget* editor,
const QModelIndex& index) const
{
if (!index.isValid())
{
return;
}
QLineEdit* lineEdit = static_cast<QLineEdit*>(editor);
QString val = index.data(Qt::DisplayRole).toString();
lineEdit->setText(val);
}