Skip to content

Commit 17c125b

Browse files
committed
Plugins::WakeOnLan: add toolbar
1 parent e0648ff commit 17c125b

5 files changed

Lines changed: 47 additions & 9 deletions

File tree

Plugins/WakeOnLan/FrmWakeOnLan.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Author: Kang Lin <kl222@126.com>
2+
13
#include <QLoggingCategory>
24
#include <QMessageBox>
35

@@ -54,7 +56,7 @@ CFrmWakeOnLan::CFrmWakeOnLan(CWakeOnLanModel *pModel, QWidget *parent)
5456
QHeaderView::ResizeToContents:3 根据内容改变列宽,用户与程序不能改变列宽
5557
*/
5658
ui->tableView->horizontalHeader()->setSectionResizeMode(
57-
QHeaderView::Interactive);
59+
QHeaderView::ResizeToContents);
5860
//以下设置列宽函数必须要数据加载完成后使用,才能应用
5961
//See: https://blog.csdn.net/qq_40450386/article/details/86083759
6062
//ui->tableView->resizeColumnsToContents(); //设置所有列宽度自适应内容
@@ -91,6 +93,11 @@ QModelIndexList CFrmWakeOnLan::GetSelect()
9193
return ui->tableView->selectionModel()->selectedRows();
9294
}
9395

96+
QToolBar* CFrmWakeOnLan::GetToolBar()
97+
{
98+
return ui->toolBar;
99+
}
100+
94101
bool CFrmWakeOnLan::eventFilter(QObject *watched, QEvent *event)
95102
{
96103
if(ui->tableView == watched)

Plugins/WakeOnLan/FrmWakeOnLan.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// Author: Kang Lin <kl222@126.com>
2+
13
#ifndef FRMWAKEONLAN_H
24
#define FRMWAKEONLAN_H
35

46
#include <QWidget>
5-
7+
#include <QToolBar>
68
#include "WakeOnLanModel.h"
79

810
namespace Ui {
@@ -19,6 +21,8 @@ class CFrmWakeOnLan : public QWidget
1921
~CFrmWakeOnLan();
2022
QModelIndex GetCurrentIndex();
2123
QModelIndexList GetSelect();
24+
QToolBar* GetToolBar();
25+
2226
public Q_SLOTS:
2327
void slotRemoveRow();
2428
Q_SIGNALS:

Plugins/WakeOnLan/FrmWakeOnLan.ui

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout">
1717
<item row="0" column="0">
18+
<widget class="QToolBar" name="toolBar">
19+
<property name="windowTitle">
20+
<string>toolBar</string>
21+
</property>
22+
<attribute name="toolBarArea">
23+
<enum>TopToolBarArea</enum>
24+
</attribute>
25+
<attribute name="toolBarBreak">
26+
<bool>false</bool>
27+
</attribute>
28+
</widget>
29+
</item>
30+
<item row="1" column="0">
1831
<widget class="QTableView" name="tableView">
1932
<property name="sortingEnabled">
2033
<bool>false</bool>

Plugins/WakeOnLan/OperateWakeOnLan.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ int COperateWakeOnLan::Initial()
4747
if(!m_pModel)
4848
return -1;
4949
m_pView = new CFrmWakeOnLan(m_pModel);
50-
if(!m_pView) return -2;
50+
if(!m_pView) return -1;
51+
QToolBar* pToolBar = m_pView->GetToolBar();
52+
if(!pToolBar) return -1;
5153
m_pView->setWindowTitle(plugin->Name());
54+
5255
check = connect(m_pView, SIGNAL(sigViewerFocusIn(QWidget*)),
5356
this, SIGNAL(sigViewerFocusIn(QWidget*)));
5457
Q_ASSERT(check);
@@ -72,12 +75,13 @@ int COperateWakeOnLan::Initial()
7275
});
7376
m_Menu.addSeparator();
7477

75-
m_Menu.addAction(QIcon::fromTheme("view-refresh"), tr("Refresh"),
78+
QAction* pRefresh = m_Menu.addAction(QIcon::fromTheme("view-refresh"), tr("Refresh"),
7679
this, [&](){
7780
foreach(auto p, m_pModel->m_Data)
7881
m_Arp.GetMac(p);
7982
});
80-
m_Menu.addAction(
83+
pToolBar->addAction(pRefresh);
84+
QAction* pMac = m_Menu.addAction(
8185
QIcon::fromTheme("mac"), tr("Get mac address"),
8286
this, [&](){
8387
if(!m_pModel || !m_pView)
@@ -89,7 +93,8 @@ int COperateWakeOnLan::Initial()
8993
p->SetHostState(CParameterWakeOnLan::HostState::GetMac);
9094
}
9195
});
92-
m_Menu.addAction(
96+
pToolBar->addAction(pMac);
97+
QAction* pWal = m_Menu.addAction(
9398
QIcon::fromTheme("lan"), tr("Wake on lan"),
9499
this, [&](){
95100
if(!m_pModel || !m_pView)
@@ -101,11 +106,14 @@ int COperateWakeOnLan::Initial()
101106
p->SetHostState(CParameterWakeOnLan::HostState::WakeOnLan);
102107
}
103108
});
109+
pToolBar->addAction(pWal);
110+
pToolBar->addSeparator();
104111
m_Menu.addSeparator();
105112

106-
m_Menu.addAction(QIcon::fromTheme("list-add"), tr("Add"),
113+
QAction* pAdd = m_Menu.addAction(QIcon::fromTheme("list-add"), tr("Add"),
107114
this, SLOT(slotAdd()));
108-
m_Menu.addAction(QIcon::fromTheme("document-edit"), tr("Edit"),
115+
pToolBar->addAction(pAdd);
116+
QAction* pEdit = m_Menu.addAction(QIcon::fromTheme("document-edit"), tr("Edit"),
109117
this, [&](){
110118
QSharedPointer<CParameterWakeOnLan> para
111119
= m_pModel->GetData(m_pView->GetCurrentIndex());
@@ -120,8 +128,10 @@ int COperateWakeOnLan::Initial()
120128
dlg.SetParameter(para.data());
121129
RC_SHOW_WINDOW(&dlg);
122130
});
123-
m_Menu.addAction(QIcon::fromTheme("list-remove"), tr("Remove"),
131+
pToolBar->addAction(pEdit);
132+
QAction* pRemove = m_Menu.addAction(QIcon::fromTheme("list-remove"), tr("Remove"),
124133
m_pView, SLOT(slotRemoveRow()));
134+
pToolBar->addAction(pRemove);
125135

126136
return 0;
127137
}

Plugins/WakeOnLan/WakeOnLanModel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ int CWakeOnLanModel::AddItem(QSharedPointer<CParameterWakeOnLan> para)
192192
if(!para)
193193
return -1;
194194
QString szIp = para->m_Net.GetHost();
195+
if(szIp.isEmpty()) {
196+
qCritical(log) << "The ip is empty";
197+
return -1;
198+
}
195199
foreach(auto p, m_Data)
196200
{
197201
if(p->m_Net.GetHost() == szIp){

0 commit comments

Comments
 (0)