1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: use const and QStringLiteral

This commit is contained in:
TriKriSta 2018-07-08 14:02:03 +03:00
parent 17a97f1ff6
commit ea8bbfd8a5
9 changed files with 37 additions and 58 deletions

View File

@ -742,13 +742,13 @@ void RawDatabase::regexpSensitive(sqlite3_context* ctx, int argc, sqlite3_value*
void RawDatabase::regexp(sqlite3_context* ctx, int argc, sqlite3_value** argv, const QRegularExpression::PatternOptions cs)
{
QRegularExpression regex;
QString str1((const char*)sqlite3_value_text(argv[0]));
QString str2((const char*)sqlite3_value_text(argv[1]));
const QString str1(reinterpret_cast<const char*>(sqlite3_value_text(argv[0])));
const QString str2(reinterpret_cast<const char*>(sqlite3_value_text(argv[1])));
regex.setPattern(str1);
regex.setPatternOptions(cs);
bool b = str2.contains(regex);
const bool b = str2.contains(regex);
if (b) {
sqlite3_result_int(ctx, 1);

View File

@ -388,7 +388,6 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi
.arg(message)
.arg(period);
qDebug() << "mes:" << queryText;
db->execNow({queryText, rowCallback});
if (!counts.isEmpty()) {
return counts[0];

View File

@ -503,12 +503,12 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param
searchPoint = QPoint(1, -1);
bool b = (parameter.period == PeriodSearch::WithTheFirst);
bool b1 = (parameter.period == PeriodSearch::AfterDate);
if (b || b1) {
if (b || (b1 && parameter.date < getFirstDate())) {
QString pk = f->getPublicKey().toString();
if ((b || parameter.date >= history->getStartDateChatHistory(pk).date()) &&
const bool isFirst = (parameter.period == PeriodSearch::WithTheFirst);
const bool isAfter = (parameter.period == PeriodSearch::AfterDate);
if (isFirst || isAfter) {
if (isFirst || (isAfter && parameter.date < getFirstDate())) {
const QString pk = f->getPublicKey().toString();
if ((isFirst || parameter.date >= history->getStartDateChatHistory(pk).date()) &&
loadHistory(phrase, parameter)) {
return;
@ -518,7 +518,7 @@ void ChatForm::searchInBegin(const QString& phrase, const ParameterSearch& param
onSearchDown(phrase, parameter);
} else {
if (parameter.period == PeriodSearch::BeforeDate && parameter.date < getFirstDate()) {
QString pk = f->getPublicKey().toString();
const QString pk = f->getPublicKey().toString();
if (parameter.date >= history->getStartDateChatHistory(pk).date() && loadHistory(phrase, parameter)) {
return;
}
@ -553,8 +553,8 @@ void ChatForm::onSearchUp(const QString& phrase, const ParameterSearch& paramete
bool isSearch = searchInText(phrase, parameter, true);
if (!isSearch) {
QString pk = f->getPublicKey().toString();
QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
const QString pk = f->getPublicKey().toString();
const QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
if (!newBaseDate.isValid()) {
return;
@ -750,7 +750,7 @@ QString getMsgAuthorDispName(const ToxPk& authorPk, const QString& dispName)
void ChatForm::loadHistoryDefaultNum(bool processUndelivered)
{
QString pk = f->getPublicKey().toString();
const QString pk = f->getPublicKey().toString();
QList<History::HistMessage> msgs = history->getChatHistoryDefaultNum(pk);
if (!msgs.isEmpty()) {
earliestMessage = msgs.first().timestamp;
@ -1075,8 +1075,8 @@ void ChatForm::SendMessageStr(QString msg)
bool ChatForm::loadHistory(const QString& phrase, const ParameterSearch& parameter)
{
QString pk = f->getPublicKey().toString();
QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
const QString pk = f->getPublicKey().toString();
const QDateTime newBaseDate = history->getDateWhereFindPhrase(pk, earliestMessage, phrase, parameter);
if (newBaseDate.isValid() && getFirstDate().isValid() && newBaseDate.date() < getFirstDate()) {
searchAfterLoadHistory = true;

View File

@ -948,8 +948,8 @@ void GenericChatForm::onSearchTriggered()
void GenericChatForm::onContinueSearch()
{
QString phrase = searchForm->getSearchPhrase();
ParameterSearch parameter = searchForm->getParameterSearch();
const QString phrase = searchForm->getSearchPhrase();
const ParameterSearch parameter = searchForm->getParameterSearch();
if (!phrase.isEmpty() && searchAfterLoadHistory) {
if (parameter.period == PeriodSearch::WithTheFirst || parameter.period == PeriodSearch::AfterDate) {
searchAfterLoadHistory = false;

View File

@ -13,11 +13,10 @@ SearchSettingsForm::SearchSettingsForm(QWidget *parent) :
ui->startDateLabel->setEnabled(false);
ui->choiceDateButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
ui->choiceDateButton->setObjectName("choiceDateButton");
ui->choiceDateButton->setObjectName(QStringLiteral("choiceDateButton"));
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
ui->startDateLabel->setStyleSheet("QLabel{color: #ddd;}");
isUpdate = false;
ui->startDateLabel->setStyleSheet(QStringLiteral("QLabel{color: #ddd;}")); // TODO: need use a style file (.css)
connect(ui->startSearchComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SearchSettingsForm::onStartSearchSelected);
@ -77,7 +76,7 @@ ParameterSearch SearchSettingsForm::getParameterSearch()
void SearchSettingsForm::updateStartDateLabel()
{
ui->startDateLabel->setText(startDate.toString("dd.MM.yyyy"));
ui->startDateLabel->setText(startDate.toString(QStringLiteral("dd.MM.yyyy")));
}
void SearchSettingsForm::setUpdate(const bool isUpdate)
@ -92,10 +91,10 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
ui->choiceDateButton->setEnabled(true);
ui->startDateLabel->setEnabled(true);
ui->choiceDateButton->setProperty("state", "green");
ui->choiceDateButton->setProperty("state", QStringLiteral("green"));
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
ui->startDateLabel->setStyleSheet("QLabel{color: #000;}");
ui->startDateLabel->setStyleSheet(QStringLiteral("QLabel{color: #000;}"));
if (startDate.isNull()) {
startDate = QDate::currentDate();
@ -106,10 +105,10 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
ui->choiceDateButton->setEnabled(false);
ui->startDateLabel->setEnabled(false);
ui->choiceDateButton->setProperty("state", "");
ui->choiceDateButton->setProperty("state", QString());
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));
ui->startDateLabel->setStyleSheet("QLabel{color: #ddd;}");
ui->startDateLabel->setStyleSheet(QStringLiteral("QLabel{color: #ddd;}"));
}
setUpdate(true);
@ -117,6 +116,7 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
void SearchSettingsForm::onRegisterClicked(const bool checked)
{
Q_UNUSED(checked)
setUpdate(true);
}

View File

@ -21,7 +21,7 @@ public:
private:
Ui::SearchSettingsForm *ui;
QDate startDate;
bool isUpdate;
bool isUpdate{false};
void updateStartDateLabel();
void setUpdate(const bool isUpdate);

View File

@ -33,9 +33,6 @@ SearchForm::SearchForm(QWidget* parent) : QWidget(parent)
settings = new SearchSettingsForm();
settings->setVisible(false);
isActiveSettings = false;
isChangedPhrase = false;
settingsButton = createButton("searchSettingsButton", "green");
upButton = createButton("searchUpButton", "green");
downButton = createButton("searchDownButton", "green");
@ -133,12 +130,11 @@ ParameterSearch SearchForm::getAndCheckParametrSearch()
void SearchForm::changedSearchPhrase(const QString& text)
{
QString l = text.right(1);
if (searchPhrase == text) {
return;
}
QString l = text.right(1);
if (!l.isEmpty() && l != " " && l[0].isSpace()) {
searchLine->setText(searchPhrase);
return;
@ -191,9 +187,9 @@ void SearchForm::clickedSearch()
settings->setVisible(isActiveSettings);
if (isActiveSettings) {
settingsButton->setProperty("state", "red");
settingsButton->setProperty("state", QStringLiteral("red"));
} else {
settingsButton->setProperty("state", "green");
settingsButton->setProperty("state", QStringLiteral("green"));
changedButtons(false);
}
settingsButton->setStyleSheet(Style::getStylesheet(QStringLiteral(":/ui/chatForm/buttons.css")));

View File

@ -58,8 +58,8 @@ private:
QString searchPhrase;
ParameterSearch parameter;
bool isActiveSettings;
bool isChangedPhrase;
bool isActiveSettings{false};
bool isChangedPhrase{false};
private slots:
void changedSearchPhrase(const QString& text);

View File

@ -21,31 +21,15 @@ enum class PeriodSearch {
};
struct ParameterSearch {
FilterSearch filter;
PeriodSearch period;
FilterSearch filter{FilterSearch::None};
PeriodSearch period{PeriodSearch::None};
QDate date;
bool isUpdate;
ParameterSearch() {
filter = FilterSearch::None;
period = PeriodSearch::None;
isUpdate = false;
}
bool isUpdate{false};
bool operator ==(const ParameterSearch& other) {
if (this->filter != other.filter) {
return false;
}
if (this->period != other.period) {
return false;
}
if (this->date != other.date) {
return false;
}
return true;
return filter == other.filter &&
period == other.period &&
date == other.date;
}
bool operator !=(const ParameterSearch& other) {