File indexing completed on 2024-05-05 04:39:18
0001 /* 0002 SPDX-FileCopyrightText: 2018 Anton Anikin <anton@anikin.xyz> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "commandlinewidget.h" 0008 #include "ui_commandlinewidget.h" 0009 0010 #include <QFontDatabase> 0011 #include <QLineEdit> 0012 0013 namespace Clazy 0014 { 0015 0016 CommandLineWidget::CommandLineWidget(QWidget* parent) 0017 : QWidget(parent) 0018 , m_ui(new Ui::CommandLineWidget) 0019 { 0020 m_ui->setupUi(this); 0021 m_ui->cmdEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); 0022 0023 connect(m_ui->cmdFilter, &QLineEdit::textChanged, this, &CommandLineWidget::updateCommandLine); 0024 connect(m_ui->cmdBreak, &QCheckBox::stateChanged, this, &CommandLineWidget::updateCommandLine); 0025 } 0026 0027 CommandLineWidget::~CommandLineWidget() = default; 0028 0029 void CommandLineWidget::setText(const QString& text) 0030 { 0031 if (m_text != text) { 0032 m_text = text; 0033 updateCommandLine(); 0034 } 0035 } 0036 0037 void CommandLineWidget::updateCommandLine() 0038 { 0039 auto commandLine = m_text; 0040 if (m_ui->cmdBreak->isChecked()) { 0041 commandLine.replace(QLatin1String(" -"), QLatin1String("\n-")); 0042 commandLine.replace(QLatin1String(","), QLatin1String("\n,")); 0043 } 0044 0045 auto filterText = m_ui->cmdFilter->text(); 0046 if (!filterText.isEmpty()) { 0047 QStringList lines = commandLine.split(QLatin1Char('\n')); 0048 QMutableStringListIterator i(lines); 0049 0050 while (i.hasNext()) { 0051 if (!i.next().contains(filterText)) { 0052 i.remove(); 0053 } 0054 } 0055 0056 commandLine = lines.join(QLatin1Char('\n')); 0057 } 0058 0059 m_ui->cmdEdit->setPlainText(commandLine); 0060 } 0061 0062 } 0063 0064 #include "moc_commandlinewidget.cpp"