Commit c20bb537 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'fortify' into 'master'

Fortify changes

See merge request !83
parents 7094e35f 17cc6531
Pipeline #71745 passed with stages
in 16 minutes and 48 seconds
......@@ -131,21 +131,43 @@ std::string remove_extra_whitespace(const std::string &inputStr)
struct std::tm utc_to_time(const std::string &time, int &zone, int &daylight)
{
int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0;
int count = sscanf(time.c_str(), "%d-%d-%dT%d:%d:%d-%d:%d", &year, &month,
&day, &hour, &minute, &second, &zone, &daylight);
(void)sizeof(count);
int times[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int count = 0;
// count = sscanf(time.c_str(), "%d-%d-%dT%d:%d:%d-%d:%d", &year, &month,
// &day, &hour, &minute, &second, &zone, &daylight);
size_t start = 0;
for (size_t i = 0; i < time.size(); i++)
{
if (time[i] < '0' || time[i] > '9')
{
try
{
times[count] = std::stoi(time.substr(start, i - start));
}
catch (...)
{
times[count] = 0;
}
start = i + 1;
count++;
}
}
radix_line("utc_to_time elements: " << count);
struct std::tm res;
res.tm_year = year;
res.tm_mon = month;
res.tm_mday = day;
res.tm_hour = hour;
res.tm_min = minute;
res.tm_sec = second;
res.tm_year = times[0];
res.tm_mon = times[1];
res.tm_mday = times[2];
res.tm_hour = times[3];
res.tm_min = times[4];
res.tm_sec = times[5];
zone = times[6];
daylight = times[7];
res.tm_isdst = daylight;
radix_line("Parsed time:" << year << "-" << month << "-" << day << "T" << hour
<< ":" << minute << ":" << second << "-" << zone
radix_line("Parsed time:" << res.tm_year << "-" << res.tm_mon << "-"
<< res.tm_mday << "T" << res.tm_hour << ":"
<< res.tm_min << ":" << res.tm_sec << "-" << zone
<< ":" << daylight);
return res;
}
......
......@@ -16,15 +16,15 @@ class NavigationActionManager::PImpl
~PImpl();
};
NavigationActionManager::PImpl::~PImpl() {}
NavigationActionManager::NavigationActionManager(QObject *parent)
: QObject(parent)
, p(new PImpl(), [](PImpl *impl) { delete impl; })
, p(new PImpl)
{
}
void NavigationActionManager::deleter(PImpl *impl) { delete impl; }
NavigationActionManager::PImpl::~PImpl() {}
NavigationActionManager::~NavigationActionManager() { delete p; }
void NavigationActionManager::registerAction(NavigationItem *item, QString text,
std::function<void()> functor)
......
......@@ -17,6 +17,7 @@ class RADIX_PUBLIC NavigationActionManager : public QObject
Q_OBJECT
public:
NavigationActionManager(QObject *parent = nullptr);
~NavigationActionManager();
void registerAction(NavigationItem *item, QString text,
std::function<void()> functor);
......@@ -24,8 +25,7 @@ class RADIX_PUBLIC NavigationActionManager : public QObject
private:
class PImpl;
std::unique_ptr<PImpl, void (*)(PImpl *)> p;
static void deleter(PImpl *impl);
PImpl *p;
};
} // namespace radix
......
......@@ -19,26 +19,26 @@ class NavigationItem::PImpl
NavigationItem::PImpl::~PImpl() { qDeleteAll(children); }
NavigationItem::NavigationItem(QVariant data, NavigationItem *parentItem)
: p(new PImpl(), deleter)
: p(new PImpl())
{
p->parent = parentItem;
p->data.append(data);
}
NavigationItem::NavigationItem(QList<QVariant> data, NavigationItem *parentItem)
: p(new PImpl(), deleter)
: p(new PImpl())
{
p->parent = parentItem;
p->data = data;
}
NavigationItem::NavigationItem(NavigationItem *parentItem)
: p(new PImpl(), deleter)
: p(new PImpl())
{
p->parent = parentItem;
}
void NavigationItem::deleter(PImpl *impl) { delete impl; }
NavigationItem::~NavigationItem() { delete p; }
int NavigationItem::type() const { return p->type; }
......
......@@ -13,6 +13,7 @@ class RADIX_PUBLIC NavigationItem
NavigationItem(QVariant data, NavigationItem *parentItem = nullptr);
NavigationItem(QList<QVariant> data, NavigationItem *parentItem = nullptr);
NavigationItem(NavigationItem *parentItem = nullptr);
~NavigationItem();
int type() const;
void setType(int type);
......@@ -29,8 +30,7 @@ class RADIX_PUBLIC NavigationItem
private:
class PImpl;
std::unique_ptr<PImpl, void (*)(PImpl *)> p;
static void deleter(PImpl *impl);
PImpl *p;
};
} // namespace radix
......
......@@ -21,12 +21,12 @@ NavigationModel::PImpl::~PImpl()
}
NavigationModel::NavigationModel(QObject* parent)
: QAbstractItemModel(parent)
, p(new PImpl(), deleter)
, p(new PImpl())
{
p->root = new NavigationItem();
}
void NavigationModel::deleter(PImpl* impl) { delete impl; }
NavigationModel::~NavigationModel() { delete p; }
QVariant NavigationModel::data(const QModelIndex& index, int role) const
{
......
......@@ -16,6 +16,7 @@ class RADIX_PUBLIC NavigationModel : public QAbstractItemModel
Q_OBJECT
public:
NavigationModel(QObject *parent = nullptr);
~NavigationModel();
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value,
......@@ -37,8 +38,7 @@ class RADIX_PUBLIC NavigationModel : public QAbstractItemModel
private:
class PImpl;
std::unique_ptr<PImpl, void (*)(PImpl *)> p;
static void deleter(PImpl *impl);
PImpl *p;
};
} // namespace radix
......
......@@ -15,12 +15,10 @@
#include <QLineEdit>
#include <QMenu>
#include <QMessageBox>
#include <QShortcut>
#include <QStandardItemModel>
#include <QTextDocument>
#include <QToolTip>
#include <QTreeView>
#include <QVBoxLayout>
#include <QtDebug>
namespace radix
......@@ -34,11 +32,14 @@ class RADIX_PUBLIC NavigationItemSortFilterProxyModel::PImpl
NavigationItemSortFilterProxyModel::NavigationItemSortFilterProxyModel(
QObject* parent)
: QSortFilterProxyModel(parent)
, p(new PImpl(), deleter)
, p(new PImpl())
{
}
void NavigationItemSortFilterProxyModel::deleter(PImpl* impl) { delete impl; }
NavigationItemSortFilterProxyModel::~NavigationItemSortFilterProxyModel()
{
delete p;
}
bool NavigationItemSortFilterProxyModel::accepts(const QModelIndex& index) const
{
......@@ -87,13 +88,13 @@ class RADIX_PUBLIC NavigationWidget::PImpl
NavigationWidget::NavigationWidget(QWidget* parent)
: QWidget(parent)
, p(new PImpl(), deleter)
, p(new PImpl())
{
initMembers();
initLayout();
}
void NavigationWidget::deleter(PImpl* impl) { delete impl; }
NavigationWidget::~NavigationWidget() { delete p; }
NavigationModel* NavigationWidget::navigationModel() { return p->model; }
......@@ -116,10 +117,9 @@ void NavigationWidget::contextMenuRequested(QPoint point)
void NavigationWidget::initLayout()
{
auto vlayout = new QVBoxLayout(this);
vlayout->addWidget(p->filter);
vlayout->addWidget(p->view);
mVertLayout = new QVBoxLayout(this);
mVertLayout->addWidget(p->filter);
mVertLayout->addWidget(p->view);
}
void NavigationWidget::initMembers()
......@@ -144,18 +144,18 @@ void NavigationWidget::initMembers()
p->proxy->setSourceModel(p->model);
// shortcuts
auto activateEnter = new QShortcut(p->view);
auto activateReturn = new QShortcut(p->view);
auto collapseBranch = new QShortcut(p->view);
mActivateEnter = new QShortcut(p->view);
mActivateReturn = new QShortcut(p->view);
mCollapseBranch = new QShortcut(p->view);
activateEnter->setContext(Qt::WidgetShortcut);
activateEnter->setKey(Qt::Key_Enter);
mActivateEnter->setContext(Qt::WidgetShortcut);
mActivateEnter->setKey(Qt::Key_Enter);
activateReturn->setContext(Qt::WidgetShortcut);
activateReturn->setKey(Qt::Key_Return);
mActivateReturn->setContext(Qt::WidgetShortcut);
mActivateReturn->setKey(Qt::Key_Return);
collapseBranch->setContext(Qt::WidgetShortcut);
collapseBranch->setKey(Qt::Key_Left);
mCollapseBranch->setContext(Qt::WidgetShortcut);
mCollapseBranch->setKey(Qt::Key_Left);
//
// connect signals/slots
......
#ifndef RADIX_RADIXWIDGETS_NAVIGATIONWIDGET_HH_
#define RADIX_RADIXWIDGETS_NAVIGATIONWIDGET_HH_
#include <QShortcut>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStyledItemDelegate>
#include <QVBoxLayout>
#include <QWidget>
#include "radixcore/visibility.hh"
......@@ -29,6 +31,7 @@ class RADIX_PUBLIC NavigationItemSortFilterProxyModel
public:
NavigationItemSortFilterProxyModel(QObject* parent = nullptr);
~NavigationItemSortFilterProxyModel();
public slots:
void clearCache();
......@@ -39,8 +42,7 @@ class RADIX_PUBLIC NavigationItemSortFilterProxyModel
private:
bool accepts(const QModelIndex& index) const;
class PImpl;
std::unique_ptr<PImpl, void (*)(PImpl*)> p;
static void deleter(PImpl* impl);
PImpl* p;
};
class RADIX_PUBLIC NavigationWidget : public QWidget
......@@ -49,6 +51,7 @@ class RADIX_PUBLIC NavigationWidget : public QWidget
public:
NavigationWidget(QWidget* parent = nullptr);
~NavigationWidget();
void collapse(QStandardItem* item);
......@@ -69,13 +72,15 @@ class RADIX_PUBLIC NavigationWidget : public QWidget
void itemUnchecked(const QModelIndex& index);
private:
QVBoxLayout* mVertLayout;
QShortcut *mActivateEnter, *mActivateReturn, *mCollapseBranch;
void initLayout();
void initMembers();
class PImpl;
std::unique_ptr<PImpl, void (*)(PImpl*)> p;
static void deleter(PImpl* impl);
PImpl* p;
};
} // namespace radix
......
......@@ -4,12 +4,9 @@
#include <QApplication>
#include <QDesktopWidget>
#include <QGridLayout>
#include <QKeyEvent>
#include <QPoint>
#include <QPushButton>
#include <QRect>
#include <QSignalMapper>
#define NEXT_ROW_MARKER 0
namespace radix
......@@ -23,15 +20,15 @@ struct KeyboardLayoutEntry
const KeyboardLayoutEntry keyboardLayout[] = {{Qt::Key_7, "7"},
{Qt::Key_8, "8"},
{Qt::Key_9, "9"},
{NEXT_ROW_MARKER, 0},
{NEXT_ROW_MARKER, nullptr},
{Qt::Key_4, "4"},
{Qt::Key_5, "5"},
{Qt::Key_6, "6"},
{NEXT_ROW_MARKER, 0},
{NEXT_ROW_MARKER, nullptr},
{Qt::Key_1, "1"},
{Qt::Key_2, "2"},
{Qt::Key_3, "3"},
{NEXT_ROW_MARKER, 0},
{NEXT_ROW_MARKER, nullptr},
{Qt::Key_0, "0"},
{Qt::Key_Period, "."},
{Qt::Key_Backspace, "Backspace"}};
......@@ -53,12 +50,12 @@ QString keyToCharacter(int key)
NumberPadWidget::NumberPadWidget(QWidget *parent)
: QLineEdit(parent)
{
QSignalMapper *mapper = new QSignalMapper(this);
connect(mapper, SIGNAL(mapped(int)), SLOT(buttonClicked(int)));
mMapper = new QSignalMapper(this);
connect(mMapper, SIGNAL(mapped(int)), SLOT(buttonClicked(int)));
// add widget containing
mNumberWidget = new QWidget(this);
QGridLayout *numLayout = new QGridLayout(mNumberWidget);
mNumberWidget = new QWidget(this);
mNumLayout = new QGridLayout(mNumberWidget);
mNumberWidget->hide();
mNumberWidget->setWindowFlags(Qt::WindowDoesNotAcceptFocus | Qt::Tool |
......@@ -77,21 +74,22 @@ NumberPadWidget::NumberPadWidget(QWidget *parent)
col = 0;
continue;
}
QPushButton *button = new QPushButton(this);
button->setObjectName("number_pad_button");
button->setText(QString::fromLatin1(keyboardLayout[i].label));
mapper->setMapping(button, keyboardLayout[i].key);
connect(button, SIGNAL(clicked()), mapper, SLOT(map()));
numLayout->addWidget(button, row, col);
mButton = new QPushButton(this);
mButton->setObjectName("number_pad_button");
mButton->setText(QString::fromLatin1(keyboardLayout[i].label));
mMapper->setMapping(mButton, keyboardLayout[i].key);
connect(mButton, SIGNAL(clicked()), mMapper, SLOT(map()));
mNumLayout->addWidget(mButton, row, col);
col++;
}
}
void NumberPadWidget::buttonClicked(int key)
{
QLineEdit::keyPressEvent(new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier,
keyToCharacter(key)));
QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier, keyToCharacter(key));
QLineEdit::keyPressEvent(&event);
}
void NumberPadWidget::focusInEvent(QFocusEvent *event)
{
QLineEdit::focusInEvent(event);
......
#ifndef RADIX_RADIXWIDGETS_NUMBERPADWIDGET_HH_
#define RADIX_RADIXWIDGETS_NUMBERPADWIDGET_HH_
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QSignalMapper>
#include <QWidget>
#include "radixcore/visibility.hh"
......@@ -11,10 +14,13 @@ class RADIX_PUBLIC NumberPadWidget : public QLineEdit
{
Q_OBJECT
QSignalMapper* mMapper;
QWidget* mNumberWidget;
QGridLayout* mNumLayout;
QPushButton* mButton;
public:
NumberPadWidget(QWidget* parent = 0);
NumberPadWidget(QWidget* parent = nullptr);
public slots:
void focusInEvent(QFocusEvent*) override;
......
......@@ -29,11 +29,11 @@ TableView::PImpl::PImpl()
TableView::TableView(QWidget *parent)
: QTableView(parent)
, p(new PImpl(), deleter)
, p(new PImpl)
{
}
void TableView::deleter(PImpl *impl) { delete impl; }
TableView::~TableView() { delete p; }
char TableView::separator() const { return p->separator; }
......
......@@ -20,11 +20,12 @@ class RADIX_PUBLIC TableView : public QTableView
Q_OBJECT
class PImpl;
std::unique_ptr<PImpl, void (*)(PImpl *)> p;
PImpl *p;
static void deleter(PImpl *impl);
public:
TableView(QWidget *parent = nullptr);
~TableView();
char separator() const;
void setSeparator(char value);
......
......@@ -2,7 +2,6 @@
#include <iostream>
#include <QLabel>
#include <QTabBar>
#include <QToolButton>
......@@ -20,7 +19,8 @@ TabWidget::TabWidget(QWidget *parent)
mNewButton->setToolTip("Add new tab");
mNewButton->setMaximumWidth(25);
addTab(new QLabel(""), QString(""));
mLabel = new QLabel("");
addTab(mLabel, QString(""));
QWidget *newTabWidget = widget(0);
newTabWidget->setObjectName("tabwidget_new_tab");
tabBar()->setTabButton(0, QTabBar::RightSide, mNewButton);
......
#ifndef RADIX_RADIXWIDGETS_TABWIDGET_HH_
#define RADIX_RADIXWIDGETS_TABWIDGET_HH_
#include <QLabel>
#include <QPushButton>
#include <QTabWidget>
......@@ -20,6 +21,7 @@ class RADIX_PUBLIC TabWidget : public QTabWidget
private:
QPushButton *mNewButton;
QLabel *mLabel;
signals:
void addTabRequested();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment