PeriDyno 1.0.0
Loading...
Searching...
No Matches
Format.cpp
Go to the documentation of this file.
1#include "Format.h"
2
3#include <QRegularExpression>
4#include <QVector>
5#include <QTextCodec>
6
7namespace dyno
8{
9 QString FormatFieldWidgetName(std::string name)
10 {
11 QString qName = QString::fromStdString(name.c_str());
12
13 bool isChinese = qName.contains(QRegularExpression("[\u4e00-\u9fa5]"));
14
15 //If the string contains Chinese, show all the original string without splitting
16 if (isChinese)
17 {
18 return qName;
19 }
20
21 //Otherwise, slit the name by the space
22 QRegularExpression regexp("[A-Z][^A-Z]*");
23 QRegularExpressionMatchIterator match = regexp.globalMatch(qName);
24 QVector<QString> vec;
25
26 QString ret;
27 while (match.hasNext())
28 {
29 ret += match.next().captured() + " ";
30 }
31
32 return ret;
33 }
34
35 QString FormatBlockPortName(std::string name)
36 {
37 QString qName = QString::fromStdString(name.c_str());
38
39 bool isChinese = qName.contains(QRegularExpression("[\u4e00-\u9fa5]"));
40
41 //If the string contains Chinese, show all the original string without splitting
42 if (isChinese)
43 {
44 return qName;
45 }
46
47 QRegularExpression regexp0("[A-Za-z()]*");
48 QRegularExpressionMatchIterator match0 = regexp0.globalMatch(qName);
49
50 QString subStr = match0.hasNext() ? match0.next().captured() : QString("Port");
51
52 QRegularExpression regexp("[A-Z][^A-Z]*");
53 QRegularExpressionMatchIterator match = regexp.globalMatch(subStr);
54
55 QString ret;
56 while (match.hasNext())
57 {
58 ret += match.next().captured() + " ";
59 }
60
61 return ret;
62 }
63
64 QString FormatBlockCaptionName(std::string name)
65 {
66 QString qName = QString::fromStdString(name.c_str());
67
68 bool isChinese = qName.contains(QRegularExpression("[\u4e00-\u9fa5]"));
69
70 //If the string contains Chinese, show all the original string without splitting
71 if (isChinese)
72 {
73 return qName;
74 }
75
76 QRegularExpression regexp0("[A-Za-z()\\s]*");
77 QRegularExpressionMatchIterator match0 = regexp0.globalMatch(qName);
78
79 QString subStr = match0.hasNext() ? match0.next().captured() : QString("Port");
80
81 QRegularExpression regexp("[A-Za-z()\\s]*");
82 QRegularExpressionMatchIterator match = regexp.globalMatch(subStr);
83
84 QString ret;
85 while (match.hasNext())
86 {
87 ret += match.next().captured() + QString(" ");
88 }
89
90 return ret;
91 }
92
93 QString FormatDescription(std::string name)
94 {
95 QTextCodec* codec = QTextCodec::codecForName("GB2312");
96
97 QString desc = QString::fromStdString(name.c_str());
98
99// bool isChinese = qName.contains(QRegExp("[\\x4e00-\\x9fa5]+"));
100//
101// //If the string contains Chinese, show all the original string without splitting
102// if (isChinese)
103// {
104// return qName;
105// }
106
107 return desc;
108 }
109
110}
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
QString FormatBlockCaptionName(std::string name)
Definition Format.cpp:64
QString FormatDescription(std::string name)
Definition Format.cpp:93
QString FormatFieldWidgetName(std::string name)
Definition Format.cpp:9
QString FormatBlockPortName(std::string name)
Definition Format.cpp:35