QElectroTech  0.70
elementinfopartwidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "elementinfopartwidget.h"
19 
20 #include <utility>
21 #include "ui_elementinfopartwidget.h"
22 #include "searchandreplaceworker.h"
23 
25 
33 ElementInfoPartWidget::ElementInfoPartWidget(QString key, const QString& translated_key, QWidget *parent):
34  QWidget(parent),
35  ui(new Ui::ElementInfoPartWidget),
36  key_(std::move(key))
37 {
38  ui->setupUi(this);
39  ui->label_->setText(translated_key);
40  ui->m_erase_text->setVisible(false);
41 
42  connect(ui->line_edit, &QLineEdit::textEdited, this, &ElementInfoPartWidget::textEdited);
43  connect(ui->line_edit, &QLineEdit::textChanged, this, &ElementInfoPartWidget::textChanged);
44 }
45 
51 {
52  delete ui;
53 }
54 
60 void ElementInfoPartWidget::setText(const QString &txt)
61 {
62  if (m_show_erase) {
63  sarw::setupLineEdit(ui->line_edit, ui->m_erase_text, txt);
64  } else {
65  ui->line_edit->setText(txt);
66  }
67 }
68 
73 QString ElementInfoPartWidget::text() const {
74  return (ui->line_edit->text());
75 }
76 
81 void ElementInfoPartWidget::setPlaceHolderText(const QString &text) {
82  ui->line_edit->setPlaceholderText(text);
83 }
84 
90  ui->line_edit->setFocus();
91 }
92 
99  ui->line_edit->setEnabled(e);
100 }
101 
108  ui->line_edit->setDisabled(d);
109 }
110 
116  ui->m_erase_text->setVisible(visible);
117  m_show_erase = visible;
118 }
119 
125  ui->m_erase_text->setChecked(check);
126 }
127 
133  return ui->m_erase_text->checkState();
134 }
135 
137 {
138  ui->line_edit->setText(ui->m_erase_text->isChecked() ? SearchAndReplaceWorker::eraseText() : QString());
139  ui->line_edit->setDisabled(ui->m_erase_text->isChecked());
140 }
ElementInfoPartWidget(QString key, const QString &translated_key, QWidget *parent=nullptr)
ElementInfoPartWidget::ElementInfoPartWidget Constructor.
void setFocusTolineEdit()
ElementInfoPartWidget::setFocusTolineEdit Set the focus to the line edit.
void textEdited(const QString &text)
void setEraseTextChecked(bool check)
ElementInfoPartWidget::setEraseTextChecked.
void setEnabled(bool e)
ElementInfoPartWidget::setEnabled enable the line edit.
SearchAndReplaceWorker sarw
void setEraseTextVisible(bool visible)
ElementInfoPartWidget::setEraseTextVisible.
Ui::ElementInfoPartWidget * ui
void textChanged(const QString &text)
void setDisabled(bool d)
ElementInfoPartWidget::setDisabled disable the line edit.
~ElementInfoPartWidget() override
ElementInfoPartWidget::~ElementInfoPartWidget destructor.
void setText(const QString &)
ElementInfoPartWidget::setText Set text to line edit.
static void setupLineEdit(QLineEdit *l, QCheckBox *cb, QString str)
SearchAndReplaceWorker::setupLineEdit With search and replace, when the variable to edit is a text...
The SearchAndReplaceWorker class This class is the worker use to change properties when use the searc...
QString text() const
ElementInfoPartWidget::text.
void setPlaceHolderText(const QString &text)
ElementInfoPartWidget::setPlaceHolderText.
Qt::CheckState EraseTextCheckState() const
ElementInfoPartWidget::EraseTextCheckState.