generated from QuardCRT-platform/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextstatistics.cpp
More file actions
82 lines (71 loc) · 2.5 KB
/
textstatistics.cpp
File metadata and controls
82 lines (71 loc) · 2.5 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "textstatistics.h"
#include <QApplication>
#include <QMap>
#include <QMessageBox>
#include <QDialog>
#include <QVBoxLayout>
#include <QTextEdit>
#include <QLabel>
#include <QPushButton>
#include <QRegularExpression>
#include <QTranslator>
#include <QDebug>
#include "textstatisticsdialog.h"
int TextStatistics::init(QMap<QString, QString> params, QWidget *parent)
{
Q_UNUSED(params);
m_action = new QAction(tr("Text Statistics"), parent);
connect(m_action, &QAction::triggered, [&,parent](){
QMessageBox::information(parent, tr("Text Statistics"),
tr(
"Text Statistics\nThis Plugin is used to view the statistics of the selected text.\nPlease select text in the terminal and right-click to view the text statistics."
));
});
return 0;
}
QList<QAction *> TextStatistics::terminalContextAction(QString selectedText, QString workingDirectory, QMenu *parentMenu)
{
Q_UNUSED(workingDirectory);
if(selectedText.isEmpty()) {
return QList<QAction *>();
}
QList<QAction *> actions;
QAction *textStatistics = new QAction(tr("Text Statistics"), parentMenu);
actions.append(textStatistics);
connect(textStatistics, &QAction::triggered, this, [=](){
static QRegularExpression re("\\s+");
TextStatisticsDialog dialog(selectedText,
QString::number(selectedText.length()),
QString::number(selectedText.split(re, Qt::SkipEmptyParts).count()),
QString::number(selectedText.split("\n", Qt::SkipEmptyParts).count()),
QString::number(selectedText.toUtf8().size()),
parentMenu);
dialog.setWindowTitle(tr("Text Statistics"));
dialog.exec();
});
return actions;
}
void TextStatistics::setLanguage(const QLocale &language,QApplication *app) {
static QTranslator *qtTranslator = nullptr;
if(qtTranslator == nullptr) {
qtTranslator = new QTranslator(app);
} else {
app->removeTranslator(qtTranslator);
delete qtTranslator;
qtTranslator = new QTranslator(app);
}
switch(language.language()) {
case QLocale::Chinese:
if(qtTranslator->load(":/lang/textstatistics_zh_CN.qm"))
app->installTranslator(qtTranslator);
break;
default:
case QLocale::English:
if(qtTranslator->load(":/lang/textstatistics_en_US.qm"))
app->installTranslator(qtTranslator);
break;
}
}
void TextStatistics::retranslateUi() {
m_action->setText(tr("Text Statistics"));
}