Rabbit Remote Control 0.0.34
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 ui->tableView->installEventFilter(this);
17 check = connect(ui->tableView,
18 SIGNAL(customContextMenuRequested(const QPoint&)),
19 this, SIGNAL(customContextMenuRequested(const QPoint&)));
20 Q_ASSERT(check);
21 check = connect(pModel, SIGNAL(modelReset()),
22 ui->tableView, SLOT(resizeColumnsToContents()));
23 Q_ASSERT(check);
24 setWindowTitle(tr("Wake on lan"));
25 setWindowIcon(QIcon::fromTheme("lan"));
26
27 // Sort
28 check = connect(
29 ui->tableView->horizontalHeader(),
30 &QHeaderView::sectionClicked,
31 this, [&](int c){
32 if(0 == c || 1 == c) {
33 ui->tableView->horizontalHeader()->setSortIndicatorShown(true);
34 }
35 else {
36 ui->tableView->horizontalHeader()->setSortIndicatorShown(false);
37 }
38 });
39 Q_ASSERT(check);
40 check = connect(ui->tableView->horizontalHeader(),
41 &QHeaderView::sortIndicatorChanged,
42 this, [&](int logicalIndex, Qt::SortOrder order){
43 if(0 == logicalIndex || 1 == logicalIndex)
44 ui->tableView->model()->sort(logicalIndex, order);
45 });
46 Q_ASSERT(check);
47
48 ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
49 //必须在 setModel 后,才能应用
50 /*第二个参数可以为:
51 QHeaderView::Interactive :0 用户可设置,也可被程序设置成默认大小
52 QHeaderView::Fixed :2 用户不可更改列宽
53 QHeaderView::Stretch :1 根据空间,自动改变列宽,用户与程序不能改变列宽
54 QHeaderView::ResizeToContents:3 根据内容改变列宽,用户与程序不能改变列宽
55 */
56 ui->tableView->horizontalHeader()->setSectionResizeMode(
57 QHeaderView::Interactive);
58 //以下设置列宽函数必须要数据加载完成后使用,才能应用
59 //See: https://blog.csdn.net/qq_40450386/article/details/86083759
60 //ui->tableView->resizeColumnsToContents(); //设置所有列宽度自适应内容
61}
62
63CFrmWakeOnLan::~CFrmWakeOnLan()
64{
65 qDebug(log) << "CFrmWakeOnLan::~CFrmWakeOnLan()";
66 delete ui;
67}
68
69void CFrmWakeOnLan::slotRemoveRow()
70{
71 QModelIndex index = ui->tableView->currentIndex();
72 if(!index.isValid())
73 {
74 QMessageBox::information(
75 nullptr,
76 tr("Information"),
77 tr("Please select a item"));
78 return;
79 }
80
81 ui->tableView->model()->removeRow(index.row());
82}
83
84QModelIndex CFrmWakeOnLan::GetCurrentIndex()
85{
86 return ui->tableView->currentIndex();
87}
88
89QModelIndexList CFrmWakeOnLan::GetSelect()
90{
91 return ui->tableView->selectionModel()->selectedRows();
92}
93
94bool CFrmWakeOnLan::eventFilter(QObject *watched, QEvent *event)
95{
96 if(ui->tableView == watched)
97 {
98 switch(event->type()){
99 case QEvent::FocusIn:
100 {
101 //qDebug(log) << Q_FUNC_INFO << event;
102 emit sigViewerFocusIn(this);
103 return false;
104 }
105 default:
106 return false;
107 }
108 }
109 return false;
110}
void sigViewerFocusIn(QWidget *pView)
The view is focus.