Command line widget.
More...
#include <clicommand.h>
|
| void | onReturnPressed () |
| | Parse entered text. Check if the text is a number, a coordinate or a command and emit the right signal. This is a slot to allow getting key press events from other widgets. More...
|
| |
| void | onKeyPressed (QKeyEvent *event) |
| | Process key events. Browse history if up or down key is pressed. This is a slot to allow getting key press events from other widgets. More...
|
| |
Command line widget.
Definition at line 20 of file clicommand.h.
| CliCommand::CliCommand |
( |
QWidget * |
parent = 0 | ) |
|
|
explicit |
Create widget.
- Parameters
-
| parent | Pointer to parent widget |
Definition at line 8 of file clicommand.cpp.
10 ui(
new Ui::CliCommand),
19 _commands = std::make_shared<QStringListModel>();
22 _completer->setCaseSensitivity(Qt::CaseInsensitive);
23 _completer->setCompletionMode(QCompleter::InlineCompletion);
26 ui->command->setCompleter(_completer.get());
std::shared_ptr< QCompleter > _completer
std::shared_ptr< QStringListModel > _commands
void onReturnPressed()
Parse entered text. Check if the text is a number, a coordinate or a command and emit the right signa...
| CliCommand::~CliCommand |
( |
| ) |
|
| bool CliCommand::addCommand |
( |
std::string |
name | ) |
|
Add a new command.
Definition at line 33 of file clicommand.cpp.
34 if(
_commands->stringList().indexOf(name.c_str()) == -1) {
36 newList << QString(name.c_str());
std::shared_ptr< QStringListModel > _commands
| bool CliCommand::checkParam |
( |
QString |
command | ) |
|
|
private |
Definition at line 122 of file clicommand.cpp.
123 return Settings::exists(command.toStdString());
| void CliCommand::commandEntered |
( |
QString |
command | ) |
|
|
signal |
| void CliCommand::coordinateEntered |
( |
lc::geo::Coordinate |
coordinate | ) |
|
|
signal |
| void CliCommand::enterCommand |
( |
QString |
command | ) |
|
|
private |
Definition at line 103 of file clicommand.cpp.
104 auto completion =
_completer->currentCompletion();
106 if(command.compare(completion, Qt::CaseInsensitive) == 0) {
107 write(
"Command: " + completion);
112 write(QString(
"Value of %1=%2").arg(command).arg(Settings::val(command.toStdString())));
116 write(
"Command " + command +
" not found");
117 ui->history->item(
ui->history->count() - 1)->setForeground(Qt::red);
std::shared_ptr< QCompleter > _completer
void write(QString message)
Write a message in the logs.
bool checkParam(QString command)
void commandEntered(QString command)
| void CliCommand::enterCoordinate |
( |
QString |
coordinate | ) |
|
|
private |
Definition at line 126 of file clicommand.cpp.
127 lc::geo::Coordinate point;
129 bool isRelative =
false;
131 if(coordinate.indexOf(
"@") != -1) {
133 coordinate.remove(
"@");
136 if(coordinate.indexOf(
";") != -1) {
137 numbers = coordinate.split(
";");
140 numbers = coordinate.split(
",");
144 if(numbers.size() > 2) {
145 point = lc::geo::Coordinate(numbers[0].toFloat(), numbers[1].toFloat(), numbers[2].toFloat());
148 point = lc::geo::Coordinate(numbers[0].toFloat(), numbers[1].toFloat());
151 auto message = QString(
"Coordinate: x=%1; y=%2; z=%3").arg(point.x()).arg(point.y()).arg(point.z());
void coordinateEntered(lc::geo::Coordinate coordinate)
void write(QString message)
Write a message in the logs.
void relativeCoordinateEntered(lc::geo::Coordinate coordinate)
| void CliCommand::enterNumber |
( |
double |
number | ) |
|
|
private |
Definition at line 162 of file clicommand.cpp.
163 write(QString(
"Number: %1").arg(number));
void write(QString message)
Write a message in the logs.
void numberEntered(double number)
| void CliCommand::keyPressEvent |
( |
QKeyEvent * |
event | ) |
|
Definition at line 99 of file clicommand.cpp.
void onKeyPressed(QKeyEvent *event)
Process key events. Browse history if up or down key is pressed. This is a slot to allow getting key ...
| void CliCommand::numberEntered |
( |
double |
number | ) |
|
|
signal |
| void CliCommand::onKeyPressed |
( |
QKeyEvent * |
event | ) |
|
|
slot |
Process key events. Browse history if up or down key is pressed. This is a slot to allow getting key press events from other widgets.
Definition at line 167 of file clicommand.cpp.
168 switch(event->key()) {
184 ui->command->clear();
189 ui->command->event(event);
| void CliCommand::onReturnPressed |
( |
| ) |
|
|
slot |
Parse entered text. Check if the text is a number, a coordinate or a command and emit the right signal. This is a slot to allow getting key press events from other widgets.
Definition at line 52 of file clicommand.cpp.
53 auto text =
ui->command->text();
56 QRegularExpression re(
"^([a-zA-Z]{1,10}+)=([0-9]{1,50}.[0-9]{1,50})|([0-9]{1,50})$");
57 QRegularExpressionMatch match = re.match(text, 0, QRegularExpression::PartialPreferCompleteMatch);
58 bool hasMatch = match.hasMatch();
70 auto number = text.toDouble(&isNumber);
74 else if (text.indexOf(
";") != -1 || text.indexOf(
",") != -1) {
78 varFind = text.split(
"=");
79 Settings::inst = Settings::instance();
80 std::unordered_map<std::string, double>::iterator it1;
83 write(QString(
"Value of %1 = %2").arg(varFind[0]).arg(varFind[1].toFloat()));
84 Settings::setVal(varFind[0].toStdString(),varFind[1].toFloat());
87 write(QString(
"No such variable."));
void enterCoordinate(QString coordinate)
void textEntered(QString text)
void write(QString message)
Write a message in the logs.
bool checkParam(QString command)
void enterCommand(QString command)
void enterNumber(double number)
| void CliCommand::relativeCoordinateEntered |
( |
lc::geo::Coordinate |
coordinate | ) |
|
|
signal |
| void CliCommand::returnText |
( |
bool |
returnText | ) |
|
Return raw text to Lua.
- Parameters
-
| returnText | true to return raw text, false to parse text Disables text parsing. |
Definition at line 198 of file clicommand.cpp.
200 }
void returnText(bool returnText)
Return raw text to Lua.
| void CliCommand::setText |
( |
QString |
text | ) |
|
Write text in input.
- Parameters
-
| text | QString It's only used in unit tests for the moment. Maybe that can be moved to a new test class. |
Definition at line 194 of file clicommand.cpp.
195 ui->command->setText(text);
| void CliCommand::textEntered |
( |
QString |
text | ) |
|
|
signal |
| void CliCommand::write |
( |
QString |
message | ) |
|
Write a message in the logs.
- Parameters
-
Definition at line 45 of file clicommand.cpp.
46 ui->history->addItem(message);
48 delete ui->history->takeItem(0);
| std::shared_ptr<QStringListModel> CliCommand::_commands |
|
private |
| std::shared_ptr<QCompleter> CliCommand::_completer |
|
private |
| QStringList CliCommand::_history |
|
private |
| int CliCommand::_historyIndex |
|
private |
| int CliCommand::_historySize |
|
private |
| bool CliCommand::_returnText |
|
private |
| Ui::CliCommand* CliCommand::ui |
|
private |
The documentation for this class was generated from the following files: