2 #include "ui_clicommand.h"
3 #include <cad/settings.h>
6 #include <unordered_map>
19 _commands = std::make_shared<QStringListModel>();
22 _completer->setCaseSensitivity(Qt::CaseInsensitive);
23 _completer->setCompletionMode(QCompleter::InlineCompletion);
26 ui->command->setCompleter(_completer.get());
34 if(
_commands->stringList().indexOf(name.c_str()) == -1) {
36 newList << QString(name.c_str());
46 ui->history->addItem(message);
48 delete ui->history->takeItem(0);
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."));
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);
123 return Settings::exists(command.toStdString());
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());
163 write(QString(
"Number: %1").arg(number));
168 switch(event->key()) {
184 ui->command->clear();
189 ui->command->event(event);
195 ui->command->setText(text);
CliCommand(QWidget *parent=0)
Create widget.
bool addCommand(std::string name)
Add a new command.
void enterCoordinate(QString coordinate)
std::shared_ptr< QCompleter > _completer
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 textEntered(QString text)
std::shared_ptr< QStringListModel > _commands
void coordinateEntered(lc::geo::Coordinate coordinate)
void write(QString message)
Write a message in the logs.
void numberEntered(double number)
bool checkParam(QString command)
void onReturnPressed()
Parse entered text. Check if the text is a number, a coordinate or a command and emit the right signa...
void commandEntered(QString command)
void setText(QString text)
Write text in input.
void enterCommand(QString command)
void returnText(bool returnText)
Return raw text to Lua.
void enterNumber(double number)
void relativeCoordinateEntered(lc::geo::Coordinate coordinate)
void keyPressEvent(QKeyEvent *event)