ledok
This commit is contained in:
parent
6a8c7e5cad
commit
2ae750ce90
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
const int AlignRight = Qt::AlignRight | Qt::AlignVCenter;
|
const int AlignRight = Qt::AlignRight | Qt::AlignVCenter;
|
||||||
|
|
||||||
Table::Table(std::initializer_list<ColAttr> colAttrs, int rows, QWidget *parent) : NumTable{rows, (int)colAttrs.size(), parent} {
|
Table::Table(std::initializer_list<ColAttr> colAttrs, int rows, QWidget *parent) : QTableWidget{rows, (int)colAttrs.size(), parent} {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(typename std::initializer_list<ColAttr>::const_iterator it = colAttrs.begin(); it != colAttrs.end(); ++it) {
|
for(typename std::initializer_list<ColAttr>::const_iterator it = colAttrs.begin(); it != colAttrs.end(); ++it) {
|
||||||
auto item = horizontalHeaderItem(i);
|
auto item = horizontalHeaderItem(i);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QStackedLayout>
|
#include <QStackedLayout>
|
||||||
|
#include <QListWidget>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ public:
|
||||||
};
|
};
|
||||||
class Grid : public QGridLayout {
|
class Grid : public QGridLayout {
|
||||||
public:
|
public:
|
||||||
inline Grid(QWidget *parent=0) : QGridLayout(parent) {}
|
using QGridLayout::QGridLayout;
|
||||||
inline Grid(QBoxLayout *parent) {
|
inline Grid(QBoxLayout *parent) {
|
||||||
parent->addLayout(this);
|
parent->addLayout(this);
|
||||||
};
|
};
|
||||||
|
@ -71,59 +72,16 @@ inline QFont qfont(const QString &family, int pixelSize, bool bold = false, bool
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NumTable : public QTableWidget {
|
class ListWgt : public QListWidget {
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
explicit NumTable(QWidget *parent = 0) : QTableWidget{parent} {}
|
using QListWidget::QListWidget;
|
||||||
NumTable(int rows, int columns, QWidget *parent = 0) : QTableWidget{rows, columns, parent} {}
|
|
||||||
|
|
||||||
inline auto setNoEdit() {
|
using QListWidget::addItem;
|
||||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
inline auto addItem(const QString &text, const QVariant &value) {
|
||||||
return this;
|
auto item = new QListWidgetItem(text);
|
||||||
}
|
|
||||||
inline auto setColWidth(int value) {
|
|
||||||
horizontalHeader()->setDefaultSectionSize(value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
inline auto setRowHeight(int value) {
|
|
||||||
verticalHeader()->setDefaultSectionSize(value);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto setHeaderText(int column, QString text) {
|
|
||||||
auto item = horizontalHeaderItem(column);
|
|
||||||
if(item==0) setHorizontalHeaderItem(column, item = new QTableWidgetItem());
|
|
||||||
item->setText(text);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto itemValid(int row, int column) {
|
|
||||||
auto item = QTableWidget::item(row, column);
|
|
||||||
if(item==0) setItem(row, column, item = new QTableWidgetItem);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
inline auto text(int row, int column) {
|
|
||||||
auto item = QTableWidget::item(row, column);
|
|
||||||
if(item==0) return QString();
|
|
||||||
return item->text();
|
|
||||||
}
|
|
||||||
inline auto setText(int row, int column, const QString &text) {
|
|
||||||
auto item = QTableWidget::item(row, column);
|
|
||||||
if(item) item->setText(text);
|
|
||||||
else setItem(row, column, item = new QTableWidgetItem(text));
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto data(int row, int col) {
|
|
||||||
auto item = QTableWidget::item(row, col);
|
|
||||||
if(item==0) return QVariant();
|
|
||||||
return item->data(Qt::UserRole);
|
|
||||||
}
|
|
||||||
inline auto setData(int row, int col, const QVariant &value) {
|
|
||||||
auto item = QTableWidget::item(row, col);
|
|
||||||
if(item==0) setItem(row, col, item = new QTableWidgetItem);
|
|
||||||
item->setData(Qt::UserRole, value);
|
item->setData(Qt::UserRole, value);
|
||||||
return item;
|
insertItem(count(), item);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -133,12 +91,16 @@ struct ColAttr {
|
||||||
int width{0};
|
int width{0};
|
||||||
int resizeMode{-1};
|
int resizeMode{-1};
|
||||||
};
|
};
|
||||||
class Table : public NumTable {
|
class Table : public QTableWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Table(QWidget *parent = nullptr) : NumTable{parent} {}
|
using QTableWidget::QTableWidget;
|
||||||
Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = nullptr);
|
Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = 0);
|
||||||
|
|
||||||
|
inline auto setNoEdit() {
|
||||||
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
inline auto setDefs() {
|
inline auto setDefs() {
|
||||||
setSelectionBehavior(QTableWidget::SelectRows);
|
setSelectionBehavior(QTableWidget::SelectRows);
|
||||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
@ -170,13 +132,16 @@ public:
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto setHeaderText(QString column, QString text) {
|
inline auto setHeaderText(int col, QString text) {
|
||||||
auto col = mFieldMap[column];
|
|
||||||
auto item = horizontalHeaderItem(col);
|
auto item = horizontalHeaderItem(col);
|
||||||
if(item==0) setHorizontalHeaderItem(col, item = new QTableWidgetItem());
|
if(item==0) setHorizontalHeaderItem(col, item = new QTableWidgetItem());
|
||||||
item->setText(text);
|
item->setText(text);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
inline auto setHeaderText(QString column, QString text) {
|
||||||
|
auto col = mFieldMap[column];
|
||||||
|
return setHeaderText(col, text);
|
||||||
|
}
|
||||||
|
|
||||||
inline auto appendRow() {
|
inline auto appendRow() {
|
||||||
auto value = rowCount();
|
auto value = rowCount();
|
||||||
|
@ -184,64 +149,92 @@ public:
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using QTableWidget::item;
|
||||||
inline auto item(int row, QString column) {
|
inline auto item(int row, QString column) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
return QTableWidget::item(row, col);
|
return item(row, col);
|
||||||
}
|
}
|
||||||
|
inline auto itemValid(int row, int col) {
|
||||||
|
auto anitem = item(row, col);
|
||||||
|
if(anitem==0) setItem(row, col, anitem = new QTableWidgetItem);
|
||||||
|
return anitem;
|
||||||
|
}
|
||||||
|
inline auto itemValid(int row, QString column) {
|
||||||
|
auto col = mFieldMap[column];
|
||||||
|
return itemValid(row, col);
|
||||||
|
}
|
||||||
|
using QTableWidget::setItem;
|
||||||
inline void setItem(int row, QString column, QTableWidgetItem *item) {
|
inline void setItem(int row, QString column, QTableWidgetItem *item) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
QTableWidget::setItem(row, col, item);
|
setItem(row, col, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto text(int row, int col) {
|
||||||
|
auto itm = item(row, col);
|
||||||
|
if(itm==0) return QString();
|
||||||
|
return itm->text();
|
||||||
}
|
}
|
||||||
inline auto text(int row, QString column) {
|
inline auto text(int row, QString column) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
auto item = QTableWidget::item(row, col);
|
return text(row, col);
|
||||||
if(item==0) return QString();
|
}
|
||||||
return item->text();
|
|
||||||
|
inline auto setText(int row, int col, const QString &text) {
|
||||||
|
auto itm = item(row, col);
|
||||||
|
if(itm) itm->setText(text);
|
||||||
|
else setItem(row, col, itm = new QTableWidgetItem(text));
|
||||||
|
return itm;
|
||||||
}
|
}
|
||||||
inline auto setText(int row, QString column, const QString &text) {
|
inline auto setText(int row, QString column, const QString &text) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
auto item = QTableWidget::item(row, col);
|
return setText(row, col, text);
|
||||||
if(item) item->setText(text);
|
|
||||||
else QTableWidget::setItem(row, col, item = new QTableWidgetItem(text));
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline auto data(int row, int col) {
|
||||||
|
auto itm = item(row, col);
|
||||||
|
if(itm==0) return QVariant();
|
||||||
|
return itm->data(Qt::UserRole);
|
||||||
|
}
|
||||||
inline auto data(int row, QString column) {
|
inline auto data(int row, QString column) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
auto item = QTableWidget::item(row, col);
|
return data(row, col);
|
||||||
if(item==0) return QVariant();
|
}
|
||||||
return item->data(Qt::UserRole);
|
|
||||||
|
inline auto setData(int row, int col, const QVariant &value) {
|
||||||
|
auto itm = item(row, col);
|
||||||
|
if(itm==0) setItem(row, col, itm = new QTableWidgetItem);
|
||||||
|
itm->setData(Qt::UserRole, value);
|
||||||
|
return itm;
|
||||||
}
|
}
|
||||||
inline auto setData(int row, QString column, const QVariant &value) {
|
inline auto setData(int row, QString column, const QVariant &value) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
auto item = QTableWidget::item(row, col);
|
return setData(row, col, value);
|
||||||
if(item==0) QTableWidget::setItem(row, col, item = new QTableWidgetItem);
|
|
||||||
item->setData(Qt::UserRole, value);
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using QTableWidget::cellWidget;
|
||||||
inline auto cellWidget(int row, QString column) {
|
inline auto cellWidget(int row, QString column) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
return QTableWidget::cellWidget(row, col);
|
return cellWidget(row, col);
|
||||||
}
|
}
|
||||||
|
using QTableWidget::setCellWidget;
|
||||||
inline void setCellWidget(int row, QString column, QWidget *widget) {
|
inline void setCellWidget(int row, QString column, QWidget *widget) {
|
||||||
auto col = mFieldMap[column];
|
auto col = mFieldMap[column];
|
||||||
QTableWidget::setCellWidget(row, col, widget);
|
setCellWidget(row, col, widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString,int> mFieldMap;
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
inline void clearRows() {setRowCount(0);}
|
inline void clearRows() {setRowCount(0);}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int sizeHintForColumn(int column) const override;
|
int sizeHintForColumn(int column) const override;
|
||||||
|
|
||||||
|
QMap<QString,int> mFieldMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResizeEmitedWgt : public QWidget {
|
class ResizeEmitedWgt : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ResizeEmitedWgt(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) : QWidget{parent, f} {}
|
using QWidget::QWidget;
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *) override {emit resized();}
|
void resizeEvent(QResizeEvent *) override {emit resized();}
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -146,9 +146,9 @@ void ProgItem::onSetProgram() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgItem::onUsbExportProgram(){
|
void ProgItem::onUsbExportProgram(){
|
||||||
auto pDlg = new UsbDetectDialog(gMainWin);
|
UsbDetectDialog dlg(gMainWin);
|
||||||
connect(pDlg, &UsbDetectDialog::acceptData, this, &ProgItem::onUsbExportProgramPro);
|
connect(&dlg, &UsbDetectDialog::acceptData, this, &ProgItem::onUsbExportProgramPro);
|
||||||
pDlg->exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
void ProgItem::onUsbExportProgramPro(QString strPath, QString strPassword) {
|
void ProgItem::onUsbExportProgramPro(QString strPath, QString strPassword) {
|
||||||
auto waitingDlg = new WaitingDlg(mProgPanel, tr("Convertering")+" ...");
|
auto waitingDlg = new WaitingDlg(mProgPanel, tr("Convertering")+" ...");
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
#include "usbdetectdialog.h"
|
#include "usbdetectdialog.h"
|
||||||
#include "gutil/qgui.h"
|
#include "gutil/qgui.h"
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QDir>
|
#include <QStorageInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTimerEvent>
|
#include <QTimerEvent>
|
||||||
|
|
||||||
UsbDetectDialog::UsbDetectDialog(QWidget *parent) : QDialog(parent) {
|
UsbDetectDialog::UsbDetectDialog(QWidget *parent) : QDialog(parent) {
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
|
||||||
setWindowTitle(tr("Usb upgrade program"));
|
setWindowTitle(tr("Usb upgrade program"));
|
||||||
resize(240, 220);
|
resize(300, 260);
|
||||||
|
|
||||||
auto vBox = new VBox(this);
|
auto vBox = new VBox(this);
|
||||||
auto hBox = new HBox(vBox);
|
auto hBox = new HBox(vBox);
|
||||||
|
@ -23,43 +24,40 @@ UsbDetectDialog::UsbDetectDialog(QWidget *parent) : QDialog(parent) {
|
||||||
fdPassword->setPlaceholderText(tr("Input password"));
|
fdPassword->setPlaceholderText(tr("Input password"));
|
||||||
hBox->addWidget(fdPassword);
|
hBox->addWidget(fdPassword);
|
||||||
|
|
||||||
fdDrives = new QListWidget();
|
fdDrives = new ListWgt;
|
||||||
fdDrives->setSelectionRectVisible(true);
|
fdDrives->setSelectionRectVisible(true);
|
||||||
fdDrives->setProperty("ssType", "usbList");
|
|
||||||
fdDrives->setProperty("ssName", "usbListName");
|
|
||||||
vBox->addWidget(fdDrives);
|
vBox->addWidget(fdDrives);
|
||||||
|
|
||||||
hBox = new HBox(vBox);
|
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
hBox->addStretch();
|
connect(btnBox, &QDialogButtonBox::accepted, this, [this] {
|
||||||
auto bnOk = new QPushButton(tr("OK"));
|
|
||||||
bnOk->setProperty("ssType","progManageTool");
|
|
||||||
connect(bnOk, &QPushButton::clicked, this, [this] {
|
|
||||||
auto selects = fdDrives->selectedItems();
|
auto selects = fdDrives->selectedItems();
|
||||||
if(selects.count() > 0) {
|
if(selects.count() > 0) {
|
||||||
foreach(auto select, selects) emit acceptData(select->text(), fdPassword->text());
|
foreach(auto select, selects) emit acceptData(select->data(Qt::UserRole).toString(), fdPassword->text());
|
||||||
accept();
|
accept();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(fdDrives->count() <= 0) QMessageBox::warning(this, tr("Tip"),tr("No checked USB device"));
|
if(fdDrives->count() <= 0) QMessageBox::warning(this, tr("Tip"),tr("No checked USB device"));
|
||||||
else QMessageBox::warning(this, tr("Tip"),tr("please select usb device in list"));
|
else QMessageBox::warning(this, tr("Tip"),tr("please select usb device in list"));
|
||||||
});
|
});
|
||||||
hBox->addWidget(bnOk);
|
connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||||
hBox->addStretch();
|
vBox->addWidget(btnBox);
|
||||||
auto bnCancel = new QPushButton(tr("Cancel"));
|
|
||||||
bnCancel->setProperty("ssType","progManageTool");
|
|
||||||
connect(bnCancel, &QPushButton::clicked, this, &QDialog::reject);
|
|
||||||
hBox->addWidget(bnCancel);
|
|
||||||
hBox->addStretch();
|
|
||||||
|
|
||||||
detectDriver();
|
detectDriver();
|
||||||
}
|
}
|
||||||
|
#include <QDebug>
|
||||||
void UsbDetectDialog::detectDriver() {
|
void UsbDetectDialog::detectDriver() {
|
||||||
#ifdef Q_OS_WINDOWS
|
|
||||||
auto drives = QDir::drives(); //获取当前系统的盘符
|
|
||||||
#else
|
|
||||||
auto drives = QDir("/Volumes").entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
|
||||||
#endif
|
|
||||||
fdDrives->clear();
|
fdDrives->clear();
|
||||||
foreach(auto drive, drives) fdDrives->addItem(drive.fileName());
|
//#ifdef Q_OS_WINDOWS
|
||||||
|
auto volumes = QStorageInfo::mountedVolumes();
|
||||||
|
foreach(auto volume, volumes) fdDrives->addItem(volume.displayName(), volume.rootPath());
|
||||||
|
foreach(auto volume, volumes) {
|
||||||
|
qDebug() << "rootPath" << volume.rootPath();
|
||||||
|
qDebug() << "device" << volume.device();
|
||||||
|
qDebug() << "name" << volume.name();
|
||||||
|
qDebug() << "displayName" << volume.displayName();
|
||||||
|
}
|
||||||
|
//#else
|
||||||
|
// auto drives = QDir("/Volumes").entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||||
|
//foreach(auto drive, drives) fdDrives->addItem(drive.fileName(), drive.filePath());
|
||||||
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#ifndef USBDETECTDIALOG_H
|
#ifndef USBDETECTDIALOG_H
|
||||||
#define USBDETECTDIALOG_H
|
#define USBDETECTDIALOG_H
|
||||||
|
|
||||||
|
#include "gutil/qgui.h"
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QListWidget>
|
|
||||||
|
|
||||||
class UsbDetectDialog : public QDialog {
|
class UsbDetectDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -12,7 +12,7 @@ signals:
|
||||||
void acceptData(QString string1, QString string2);
|
void acceptData(QString string1, QString string2);
|
||||||
private:
|
private:
|
||||||
void detectDriver();
|
void detectDriver();
|
||||||
QListWidget *fdDrives;
|
ListWgt *fdDrives;
|
||||||
QLineEdit *fdPassword;
|
QLineEdit *fdPassword;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user