This commit is contained in:
Andrei Yankovich 2018-06-03 13:49:35 +03:00
parent 7afefc4272
commit 9faa3eca88
13 changed files with 214 additions and 76 deletions

14
source/CPP/about.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "about.h"
#include "ui_about.h"
About::About(QWidget *parent) :
QWidget(parent),
ui(new Ui::About)
{
ui->setupUi(this);
}
About::~About()
{
delete ui;
}

22
source/CPP/about.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef ABOUT_H
#define ABOUT_H
#include <QWidget>
namespace Ui {
class About;
}
class About : public QWidget
{
Q_OBJECT
public:
explicit About(QWidget *parent = 0);
~About();
private:
Ui::About *ui;
};
#endif // ABOUT_H

47
source/CPP/about.ui Normal file
View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>About</class>
<widget class="QWidget" name="About">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>244</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="logo">
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="text">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,6 +1,7 @@
#include "deploypage.h"
#include "ui_deploypage.h"
#include <QMessageBox>
#include "listviewdelegate.h"
DeployPage::DeployPage(CppManager * cpp, QWidget *parent) :
QWidget(parent),
@ -10,12 +11,29 @@ DeployPage::DeployPage(CppManager * cpp, QWidget *parent) :
m_cpp = cpp;
model = new ListModel();
ui->tableView->setModel(model);
delegate = new ListViewDelegate();
ui->tableView->setItemDelegate(delegate);
ui->tableView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->tableView->setColumnWidth(1, 40);
connect(ui->tableView, &QTableView::clicked, this, &DeployPage::clicked);
connect(ui->checkBox, &QCheckBox::stateChanged, this, &DeployPage::checkChanged);
connect(ui->deoply, &QPushButton::clicked, this, &DeployPage::deployClicked);
}
void DeployPage::clicked(QModelIndex i){
if(!ui->tableView->isEnabled()){
return;
}
if(i.column() == 1){
bool isChecked = model->data(i).toBool();
model->setData(i, !isChecked);
}
}
void DeployPage::deployClicked(){
emit deploy(model->getSelectedList());
emit deploy(model->getSelectedList(!ui->tableView->isEnabled()));
}
void DeployPage::buildFinished(){
@ -23,11 +41,12 @@ void DeployPage::buildFinished(){
}
void DeployPage::checkChanged(int e){
ui->checkBox->setEnabled(!e);
ui->tableView->setEnabled(!e);
}
DeployPage::~DeployPage()
{
delete delegate;
delete model;
delete ui;
}

View File

@ -5,6 +5,7 @@
#include "listmodel.h"
#include "mainmanager.h"
#include "cppmanager.h"
#include "listviewdelegate.h"
namespace Ui {
class DeployPage;
@ -25,10 +26,12 @@ private:
CppManager *m_cpp;
Ui::DeployPage *ui;
ListModel *model;
ListViewDelegate *delegate;
private slots:
void deployClicked();
void checkChanged(int);
void clicked(QModelIndex);
signals:
void deploy(QStringList);

View File

@ -3,31 +3,8 @@
ListModel::ListModel(QObject *parent)
: QStandardItemModel(parent)
{
}
QVariant ListModel::headerData(int section, Qt::Orientation orientation, int) const
{
if(orientation == Qt::Vertical){
switch (section) {
case 0:
return tr("lib Path");
case 1:
return tr("is Deploy");
default:
return QVariant();
break;
}
}
return QVariant();
}
int ListModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return source.size();
setColumnCount(2);
this->setHorizontalHeaderLabels(QStringList()<<tr("path")<<tr("add"));
}
QVariant ListModel::data(const QModelIndex &index, int role) const
@ -35,6 +12,18 @@ QVariant ListModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
if (role == Qt::CheckStateRole && index.column() == 1){
if (source[index.row()].second)
return Qt::Checked;
else
return Qt::Unchecked;
}
if(role == Qt::EditRole && index.column() == 1){
return source[index.row()].second;
}
if(role == Qt::DisplayRole){
switch (index.column()) {
case 0: return source[index.row()].first;
@ -54,42 +43,31 @@ bool ListModel::setData(const QModelIndex &index, const QVariant &value, int rol
return false;
}
if (data(index, role) != value) {
if (data(index, role) != value)
{
source[index.row()].second = value.toBool();
emit dataChanged(index, index, QVector<int>() << role);
emit dataChanged(index, index);
return true;
}
return false;
}
Qt::ItemFlags ListModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
if (index.column() == 1){
return Qt::ItemIsSelectable;
}
return Qt::NoItemFlags; // FIXME: Implement me!
}
void ListModel::setSource(const QStringList &_source){
beginResetModel();
source.clear();
for(const QString &i : _source){
source.push_back(QPair<QString, bool>(i, false));
}
endResetModel();
this->setRowCount(source.count());
}
QStringList ListModel::getSelectedList()const {
QStringList ListModel::getSelectedList(bool all)const {
QStringList list;
for (const QPair<QString, bool> &p: source){
if(p.second){
if(p.second || all){
list.push_back(p.first);
}
}

View File

@ -10,23 +10,15 @@ class ListModel : public QStandardItemModel
public:
explicit ListModel(QObject *parent = nullptr);
// Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
void setSource(const QStringList &source);
QStringList getSelectedList() const;
QStringList getSelectedList(bool all) const;
private:

View File

@ -0,0 +1,36 @@
#include "listviewdelegate.h"
#include <QCheckBox>
#include <QPainter>
ListViewDelegate::ListViewDelegate()
{
}
void ListViewDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const{
if (index.column() == 1)
{
QWidget *w = dynamic_cast<QWidget *>(painter->device());
if (w)
{
QItemDelegate::drawBackground( painter, option, index );
QItemDelegate::drawCheck( painter, option, option.rect, index.data(Qt::EditRole).toBool() ? Qt::Checked : Qt::Unchecked );
drawFocus(painter, option, option.rect);
}
} else {
QItemDelegate::paint(painter, option, index);
}
}
QWidget* ListViewDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const{
return QItemDelegate::createEditor(parent, option, index);
}

View File

@ -0,0 +1,18 @@
#ifndef LISTVIEWDELEGATE_H
#define LISTVIEWDELEGATE_H
#include <QItemDelegate>
class ListViewDelegate : public QItemDelegate
{
public:
ListViewDelegate();
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
};
#endif // LISTVIEWDELEGATE_H

View File

@ -45,7 +45,9 @@ SOURCES += \
mainwindow.cpp \
CPP/buildpage.cpp \
CPP/deploypage.cpp \
CPP/listmodel.cpp
CPP/listmodel.cpp \
CPP/listviewdelegate.cpp \
CPP/about.cpp
HEADERS += \
CPP/baseclass.h \
@ -58,7 +60,9 @@ HEADERS += \
mainwindow.h \
CPP/buildpage.h \
CPP/deploypage.h \
CPP/listmodel.h
CPP/listmodel.h \
CPP/listviewdelegate.h \
CPP/about.h
TRANSLATIONS += \
languages/en.ts
@ -70,4 +74,5 @@ RC_ICONS = snap/icon.ico
FORMS += \
mainwindow.ui \
CPP/buildpage.ui \
CPP/deploypage.ui
CPP/deploypage.ui \
CPP/about.ui

View File

@ -18,6 +18,7 @@ MainWindow::MainWindow(MainManager * mainManager, QWidget *parent) :
ui->stackedWidget->setCurrentIndex(0);
connect(ui->menubar, SIGNAL(build(QString,QString)), _mainManager, SLOT(prepare(QString,QString)));
connect(buidlpage, SIGNAL(build(QString,QString)), _mainManager, SLOT(prepare(QString,QString)));
connect(_mainManager->getBuild(), SIGNAL(logChanged(QString)), buidlpage, SLOT(log(QString)));
connect(_mainManager->getBuild(), SIGNAL(finished()), this, SLOT(buidlFinisfed()));
@ -26,6 +27,21 @@ MainWindow::MainWindow(MainManager * mainManager, QWidget *parent) :
connect(deployPage,SIGNAL(deploy(QStringList)), _mainManager, SLOT(deploy(QStringList)));
}
void MainWindow::newDeploy(){
ui->stackedWidget->setCurrentIndex(0);
}
void MainWindow::initMenu(){
QAction *deploy = new QAction(tr("new deploy"));
connect(deploy, SIGNAL(triggered(bool)),SLOT(newDeploy()));
ui->menubar->addAction(deploy);
QAction *about = new QAction(tr("about"));
connect(about, SIGNAL(triggered(bool)),SLOT(about()));
ui->menubar->addAction(about);
}
void MainWindow::buidlFinisfed(){
ui->stackedWidget->setCurrentIndex(1);
deployPage->buildFinished();

View File

@ -20,9 +20,13 @@ private:
BuildPage *buidlpage;
DeployPage *deployPage;
initMenu();
private slots:
void buidlFinisfed();
void stateChanged(int);
void newDeploy();
void about();
public:
explicit MainWindow(MainManager * mainManager, QWidget *parent = 0);
~MainWindow();

View File

@ -24,6 +24,7 @@
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
@ -33,24 +34,7 @@
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menusettings">
<property name="title">
<string>file</string>
</property>
<addaction name="actionsettings"/>
<addaction name="actionexit"/>
</widget>
<widget class="QMenu" name="menuabout">
<property name="title">
<string>about</string>
</property>
<addaction name="actioncontact"/>
<addaction name="actionabout"/>
</widget>
<addaction name="menusettings"/>
<addaction name="menuabout"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actioncontact">
<property name="text">
<string>contact</string>
@ -63,7 +47,7 @@
</action>
<action name="actionsettings">
<property name="text">
<string>settings</string>
<string>new deploy</string>
</property>
</action>
<action name="actionexit">