Sanitize bookmark and tag names by preventing use of forbidden characters

This commit is contained in:
0penBrain 2023-10-27 19:36:17 +02:00
parent 691ba1d563
commit 8be3dc3856
5 changed files with 121 additions and 0 deletions

View File

@ -20,6 +20,8 @@ add_source_files(SRCS_LIST
ctk/ctkRangeSlider.h
demod_options.cpp
demod_options.h
dlg_saveablestring.cpp
dlg_saveablestring.h
dockaudio.cpp
dockaudio.h
dockbookmarks.cpp

View File

@ -22,6 +22,7 @@
*/
#include "bookmarkstaglist.h"
#include "bookmarks.h"
#include "dlg_saveablestring.h"
#include <QColorDialog>
#include <stdio.h>
#include <QMenu>
@ -48,6 +49,9 @@ BookmarksTagList::BookmarksTagList(QWidget *parent, bool bShowUntagged )
setSelectionMode(QAbstractItemView::SingleSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSortingEnabled(true);
LineEditDelegateSaveableString* DelegateTagName = new LineEditDelegateSaveableString(this);
this->setItemDelegateForColumn(1, DelegateTagName);
}
void BookmarksTagList::on_cellClicked(int row, int column)

View File

@ -0,0 +1,64 @@
/* -*- c++ -*- */
/*
* Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
* https://gqrx.dk/
*
* Copyright 2023 0penBrain
*
* Gqrx is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* Gqrx is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Gqrx; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "dlg_saveablestring.h"
#include <QDebug>
#include <QLineEdit>
LineEditDelegateSaveableString::LineEditDelegateSaveableString(QObject *parent)
:QStyledItemDelegate(parent)
{
}
#include <QDebug>
QWidget *LineEditDelegateSaveableString::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
auto* editor = QStyledItemDelegate::createEditor(parent, option, index);
auto* lineedit = qobject_cast<QLineEdit*>(editor);
if (!lineedit)
{
qWarning() << __FUNCTION__ << " : " << "Editor cannot be cast to LineEdit, entry will not be validated";
}
else
{
lineedit->setValidator(new SaveableStringValidator(lineedit));
}
return editor;
}
SaveableStringValidator::SaveableStringValidator(QObject *parent)
:QValidator(parent)
{
}
QValidator::State SaveableStringValidator::validate(QString &input, int &pos) const
{
if (input.contains(';') || input.contains(','))
{
return QValidator::Invalid;
}
return QValidator::Acceptable;
}

View File

@ -0,0 +1,47 @@
/* -*- c++ -*- */
/*
* Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
* https://gqrx.dk/
*
* Copyright 2023 0penBrain
*
* Gqrx is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* Gqrx is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Gqrx; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef DLG_SAVEABLESTRING_H
#define DLG_SAVEABLESTRING_H
#include <QStyledItemDelegate>
#include <QValidator>
class LineEditDelegateSaveableString : public QStyledItemDelegate
{
Q_OBJECT
public:
LineEditDelegateSaveableString(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
//void setEditorData(QWidget *editor, const QModelIndex &index) const;
//void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
};
class SaveableStringValidator : public QValidator
{
Q_OBJECT
public:
SaveableStringValidator(QObject *parent = 0);
QValidator::State validate(QString &input, int &pos) const;
};
#endif // DLG_SAVEABLESTRING_H

View File

@ -31,6 +31,7 @@
#include "bookmarks.h"
#include "bookmarkstaglist.h"
#include "dlg_saveablestring.h"
#include "dockbookmarks.h"
#include "dockrxopt.h"
#include "qtcolorpicker.h"
@ -56,6 +57,9 @@ DockBookmarks::DockBookmarks(QWidget *parent) :
ComboBoxDelegateModulation* delegateModulation = new ComboBoxDelegateModulation(this);
ui->tableViewFrequencyList->setItemDelegateForColumn(2, delegateModulation);
LineEditDelegateSaveableString* delegateBookmarkName = new LineEditDelegateSaveableString(this);
ui->tableViewFrequencyList->setItemDelegateForColumn(1, delegateBookmarkName);
// Bookmarks Context menu
contextmenu = new QMenu(this);
// MenuItem Delete