Skip to content
Permalink
Browse files

begin abstracted tab view to make room for STIG editor

  • Loading branch information
squinky86 committed Mar 10, 2020
1 parent 0d1ed87 commit 2683201ebb228c676981e9b45478e7fe73b67c87
Showing with 134 additions and 27 deletions.
  1. +2 −0 STIGQter.pro
  2. +10 −13 src/assetview.cpp
  3. +4 −3 src/assetview.h
  4. +23 −11 src/stigqter.cpp
  5. +51 −0 src/tabviewwidget.cpp
  6. +44 −0 src/tabviewwidget.h
@@ -46,6 +46,7 @@ SOURCES += \
src/stigqter.cpp \
src/dbmanager.cpp \
src/common.cpp \
src/tabviewwidget.cpp \
src/worker.cpp \
src/workerassetckl.cpp \
src/workerccidelete.cpp \
@@ -79,6 +80,7 @@ HEADERS += \
src/dbmanager.h \
src/common.h \
src/family.h \
src/tabviewwidget.h \
src/worker.h \
src/workerassetckl.h \
src/workerccidelete.h \
@@ -59,12 +59,11 @@
* Main constructor.
*/
AssetView::AssetView(Asset &asset, QWidget *parent) :
QWidget(parent),
TabViewWidget(parent),
ui(new Ui::AssetView),
_asset(std::move(asset)),
_justification(),
_updateStatus(false),
_tabIndex(-1),
_isFiltered(false),
_parent(dynamic_cast<STIGQter *>(parent))
{
@@ -188,6 +187,15 @@ void AssetView::EnableInput()
ui->btnSaveCKL->setEnabled(true);
}

/**
* @brief AssetView::GetTabType
* @return TabType of Asset
*/
TabType AssetView::GetTabType()
{
return TabType::asset;
}

/**
* @brief AssetView::SelectSTIGs
* @param search
@@ -346,17 +354,6 @@ void AssetView::UpdateSTIGCheck(const STIGCheck &stigCheck)
ui->lblCcis->setText(ccis);
}

/**
* @brief AssetView::SetTabIndex
* @param index
*
* Keep up with which index this tab is in the interface.
*/
void AssetView::SetTabIndex(int index)
{
_tabIndex = index;
}

#ifdef USE_TESTS
void AssetView::ProcEvents()
{
@@ -32,11 +32,13 @@
#include <QTimer>
#include <QWidget>

#include "tabviewwidget.h"

namespace Ui {
class AssetView;
}

class AssetView : public QWidget
class AssetView : public TabViewWidget
{
Q_OBJECT

@@ -48,11 +50,11 @@ class AssetView : public QWidget
void DisableInput();
void Display();
void EnableInput();
TabType GetTabType();
void SelectSTIGs(const QString &search = QString());
void ShowChecks(bool countOnly = false);
void UpdateCKLCheck(const CKLCheck &cklCheck);
void UpdateSTIGCheck(const STIGCheck &stigCheck);
void SetTabIndex(int index);
#ifdef USE_TESTS
void ProcEvents();
void RunTests();
@@ -86,7 +88,6 @@ private Q_SLOTS:
QTimer _timerChecks;
QList<QShortcut*> _shortcuts;
bool _updateStatus;
int _tabIndex;
void KeyShortcut(Status action);
void SetItemColor(QListWidgetItem *i, Status stat, Severity sev);
bool _isFiltered;
@@ -321,16 +321,20 @@ void STIGQter::RunTests()

for (int j = 1; j < ui->tabDB->count(); j++)
{
auto *tmpAssetView = dynamic_cast<AssetView*>(ui->tabDB->widget(j));
auto *tmpTabView = dynamic_cast<TabViewWidget*>(ui->tabDB->widget(j));

if (tmpAssetView)
tmpAssetView->SetTabIndex(j);
if (tmpTabView)
tmpTabView->SetTabIndex(j);

ProcEvents();

//run AssetView tests
std::cout << "\tTest " << step++ << ": Running Asset Tests" << std::endl;
tmpAssetView->RunTests(); //will delete asset
if (tmpTabView->GetTabType() == TabType::asset)
{
auto *tmpAssetView = dynamic_cast<AssetView*>(tmpTabView);
tmpAssetView->RunTests(); //will delete asset
}
ProcEvents();
}
}
@@ -669,9 +673,9 @@ void STIGQter::CloseTab(int index)
for (int j = 1; j < ui->tabDB->count(); j++)
{
//reset the tab indices for the tabs that were not closed
auto *tmpAssetView = dynamic_cast<AssetView*>(ui->tabDB->widget(j));
if (tmpAssetView)
tmpAssetView->SetTabIndex(j);
auto *tmpTabView = dynamic_cast<TabViewWidget*>(ui->tabDB->widget(j));
if (tmpTabView)
tmpTabView->SetTabIndex(j);
}
DisplayAssets();
}
@@ -1060,8 +1064,12 @@ void STIGQter::EnableInput()
ui->tabDB->setEnabled(true);
for (int i = 1; i < ui->tabDB->count(); i++)
{
auto *tmpAssetView = dynamic_cast<AssetView*>(ui->tabDB->widget(i));
tmpAssetView->EnableInput();
auto *tmpTabView = dynamic_cast<TabViewWidget*>(ui->tabDB->widget(i));
if (tmpTabView->GetTabType() == TabType::asset)
{
auto *tmpAssetView = dynamic_cast<AssetView*>(tmpTabView);
tmpAssetView->EnableInput();
}
}
SelectSTIG();
}
@@ -1142,8 +1150,12 @@ void STIGQter::DisableInput()
ui->tabDB->setEnabled(false);
for (int i = 1; i < ui->tabDB->count(); i++)
{
auto *tmpAssetView = dynamic_cast<AssetView*>(ui->tabDB->widget(i));
tmpAssetView->DisableInput();
auto *tmpTabView = dynamic_cast<TabViewWidget*>(ui->tabDB->widget(i));
if (tmpTabView->GetTabType() == TabType::asset)
{
auto *tmpAssetView = dynamic_cast<AssetView*>(tmpTabView);
tmpAssetView->DisableInput();
}
}
}

@@ -0,0 +1,51 @@
/*
* STIGQter - STIG fun with Qt
*
* Copyright © 2020 Jon Hood, http://www.hoodsecurity.com/
*
* This program 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 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "tabviewwidget.h"

/**
* @brief TabViewWidget::TabViewWidget
* @param parent
*
* Main Constructor
*/
TabViewWidget::TabViewWidget(QWidget *parent) : QWidget(parent), _tabIndex(-1)
{

}

/**
* @brief TabViewWidget::SetTabIndex
* @param index
*
* Keep up with which index this tab is in the interface.
*/
void TabViewWidget::SetTabIndex(int index)
{
_tabIndex = index;
}

/**
* @brief TabViewWidget::GetTabType
* @return What type of tab this is (main, Asset, or STIG)
*/
TabType TabViewWidget::GetTabType()
{
return TabType::root;
}
@@ -0,0 +1,44 @@
/*
* STIGQter - STIG fun with Qt
*
* Copyright © 2020 Jon Hood, http://www.hoodsecurity.com/
*
* This program 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 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TABVIEWWIDGET_H
#define TABVIEWWIDGET_H

#include <QWidget>

enum TabType
{
stig = 2,
asset = 1,
root = 0
};

class TabViewWidget : public QWidget
{
Q_OBJECT
public:
explicit TabViewWidget(QWidget *parent = nullptr);
void SetTabIndex(int index);
virtual TabType GetTabType();

protected:
int _tabIndex;
};

#endif // TABVIEWWIDGET_H

0 comments on commit 2683201

Please sign in to comment.
You can’t perform that action at this time.