Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
FrmWakeOnLan.cpp
1#include <QLoggingCategory>
2#include <QMessageBox>
3
4#include "FrmWakeOnLan.h"
5#include "ui_FrmWakeOnLan.h"
6
7static Q_LOGGING_CATEGORY(log, "WakeOnLan.CFrmWakeOnLan")
8CFrmWakeOnLan::CFrmWakeOnLan(CWakeOnLanModel *pModel, QWidget *parent)
9 : QWidget(parent)
10 , ui(new Ui::CFrmWakeOnLan)
11{
12 bool check = false;
13 ui->setupUi(this);
14 ui->tableView->setModel(pModel);
15 ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu);
16 check = connect(ui->tableView,
17 SIGNAL(customContextMenuRequested(const QPoint&)),
18 this, SIGNAL(customContextMenuRequested(const QPoint&)));
19 Q_ASSERT(check);
20 check = connect(pModel, SIGNAL(modelReset()),
21 ui->tableView, SLOT(resizeColumnsToContents()));
22 Q_ASSERT(check);
23 setWindowTitle(tr("Wake on lan"));
24 setWindowIcon(QIcon::fromTheme("lan"));
25
26 // Sort
27 check = connect(
28 ui->tableView->horizontalHeader(),
29 &QHeaderView::sectionClicked,
30 this, [&](int c){
31 if(0 == c || 1 == c) {
32 ui->tableView->horizontalHeader()->setSortIndicatorShown(true);
33 }
34 else {
35 ui->tableView->horizontalHeader()->setSortIndicatorShown(false);
36 }
37 });
38 Q_ASSERT(check);
39 check = connect(ui->tableView->horizontalHeader(),
40 &QHeaderView::sortIndicatorChanged,
41 this, [&](int logicalIndex, Qt::SortOrder order){
42 if(0 == logicalIndex || 1 == logicalIndex)
43 ui->tableView->model()->sort(logicalIndex, order);
44 });
45 Q_ASSERT(check);
46
47 ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
48 //必须在 setModel 后,才能应用
49 /*第二个参数可以为:
50 QHeaderView::Interactive :0 用户可设置,也可被程序设置成默认大小
51 QHeaderView::Fixed :2 用户不可更改列宽
52 QHeaderView::Stretch :1 根据空间,自动改变列宽,用户与程序不能改变列宽
53 QHeaderView::ResizeToContents:3 根据内容改变列宽,用户与程序不能改变列宽
54 */
55 ui->tableView->horizontalHeader()->setSectionResizeMode(
56 QHeaderView::Interactive);
57 //以下设置列宽函数必须要数据加载完成后使用,才能应用
58 //See: https://blog.csdn.net/qq_40450386/article/details/86083759
59 //ui->tableView->resizeColumnsToContents(); //设置所有列宽度自适应内容
60}
61
62CFrmWakeOnLan::~CFrmWakeOnLan()
63{
64 qDebug(log) << "CFrmWakeOnLan::~CFrmWakeOnLan()";
65 delete ui;
66}
67
68void CFrmWakeOnLan::slotRemoveRow()
69{
70 QModelIndex index = ui->tableView->currentIndex();
71 if(!index.isValid())
72 {
73 QMessageBox::information(
74 nullptr,
75 tr("Information"),
76 tr("Please select a item"));
77 return;
78 }
79
80 ui->tableView->model()->removeRow(index.row());
81}
82
83QModelIndex CFrmWakeOnLan::GetCurrentIndex()
84{
85 return ui->tableView->currentIndex();
86}
87
88QModelIndexList CFrmWakeOnLan::GetSelect()
89{
90 return ui->tableView->selectionModel()->selectedRows();
91}