Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
2006 lines (1755 loc) · 76.6 KB
/
Copy pathmainwindow.cpp
File metadata and controls
2006 lines (1755 loc) · 76.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include <QDockWidget>
#include <QFileDialog>
#include <QDebug>
#include <QImageReader>
#include <QGraphicsPixmapItem>
#include <QInputDialog>
#include <QLineEdit>
#include <QSpinBox>
#include <QPushButton>
#include <QLabel>
#include <QFormLayout>
#include <QMessageBox>
#include <QElapsedTimer>
#include <QStatusBar>
#include <QToolBar>
#include <QToolButton>
#include "vocexport.h"
#include <QSpinBox>
#include <QFormLayout>
#include <QCheckBox>
#include "yoloexport.h"
#include <QTranslator>
#include <QActionGroup>
QString getQSSFile(QString fileName)
{
QFile infile(fileName);
infile.open(QIODevice::ReadOnly);
return infile.readAll();
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
golbalState.readSettingIni();
slot_changeTheme(golbalState.themeStr);
slot_changeLang(golbalState.langStr);
createMenus();
createWidges();
createToolBars();
//setupToolBarIcons();
restoreLastWorkPath();
}
MainWindow::~MainWindow()
{
}
QPixmap MainWindow::captureScene(QGraphicsScene* scene)
{
if (!scene) {
qWarning() << "Scene is null!";
return QPixmap();
}
QGraphicsPixmapItem *pixitem = nullptr;
QList<QGraphicsItem *> sitems = scene->items();
for(int i=0;i!=sitems.size();i++)
{
if(sitems[i]->type() == QGraphicsPixmapItem::Type)
{
pixitem = static_cast<QGraphicsPixmapItem*>(sitems[i]);
}
if(sitems[i]->type() == LQGraphicsRectItem::Type || sitems[i]->type() == LQGraphicsPathItem::Type)
{
auto item1 = static_cast<LQGraphicsRectItem*>(sitems[i]);
QBrush bsh = item1->brush();
QColor color1 = bsh.color();
color1.setAlpha(255);
bsh.setColor(color1);
item1->setBrush(bsh);
}
}
QPixmap tmppixmap = pixitem->pixmap();
QPixmap pixmapblack(tmppixmap.size());
pixmapblack.fill(Qt::black);
pixitem->setPixmap(pixmapblack);
// 获取场景的矩形区域
QRectF sceneRect = scene->sceneRect();
// 创建一个与场景大小相同的 QPixmap
QPixmap pixmap(sceneRect.size().toSize());
pixmap.fill(Qt::transparent); // 设置背景为透明
// 创建一个 QPainter,用于将场景渲染到 QPixmap
QPainter painter(&pixmap);
scene->render(&painter, QRectF(), sceneRect);
pixitem->setPixmap(tmppixmap);
for(int i=0;i!=sitems.size();i++)
{
if(sitems[i]->type() == LQGraphicsRectItem::Type || sitems[i]->type() == LQGraphicsPathItem::Type)
{
auto item1 = static_cast<LQGraphicsRectItem*>(sitems[i]);
QBrush bsh = item1->brush();
QColor color1 = bsh.color();
color1.setAlpha(golbalState.alpha);
bsh.setColor(color1);
item1->setBrush(bsh);
}
}
return pixmap;
}
void MainWindow::createWidges()
{
m_treeView = new LQTreeView(this);
m_listView = new LQListView(this);
m_sence = new LQGraphicsScene(this);
m_view = new LQGraphicsView(this);
m_view->setScene(m_sence);
m_slLabel = new ImageLabel;
m_slLabel->setMinimumHeight(70);
m_listWidgeLabels = new QListWidget;
m_listView->setContextMenuPolicy(Qt::CustomContextMenu);
setCentralWidget(m_view);
// 创建左侧停靠窗口
m_dockFileTree = new QDockWidget(tr("文件浏览器"), this);
m_dockFileTree->setWidget(m_treeView); // 将树视图添加到停靠窗口
m_dockFileTree->setAllowedAreas(Qt::LeftDockWidgetArea); // 允许停靠在左侧或右侧
addDockWidget(Qt::LeftDockWidgetArea, m_dockFileTree); // 将停靠窗口添加到主窗口左侧
m_dockImageList = new QDockWidget(tr("图片浏览器"), this);
m_dockImageList->setWidget(m_listView); // 将树视图添加到停靠窗口
m_dockImageList->setAllowedAreas(Qt::LeftDockWidgetArea); // 允许停靠在左侧或右侧
addDockWidget(Qt::LeftDockWidgetArea, m_dockImageList); // 将停靠窗口添加到主窗口左侧
// 并列显示两个 QDockWidget
splitDockWidget(m_dockFileTree, m_dockImageList, Qt::Horizontal);
// 禁用共享分割条
setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks);
m_dockslLabel = new QDockWidget(tr("标注缩略图"), this);
m_dockslLabel->setWidget(m_slLabel); // 将树视图添加到停靠窗口
m_dockslLabel->setAllowedAreas(Qt::RightDockWidgetArea); // 允许停靠在左侧或右侧
addDockWidget(Qt::RightDockWidgetArea, m_dockslLabel); // 将停靠窗口添加到主窗口左侧
m_dockPixInfo = new QDockWidget(tr("标注信息"), this);
m_dockPixInfo->setWidget(m_listWidgeLabels); // 将树视图添加到停靠窗口
m_dockPixInfo->setAllowedAreas(Qt::RightDockWidgetArea); // 允许停靠在左侧或右侧
addDockWidget(Qt::RightDockWidgetArea, m_dockPixInfo); // 将停靠窗口添加到主窗口左侧
viewMenu->addAction(m_dockFileTree->toggleViewAction());
viewMenu->addAction(m_dockImageList->toggleViewAction());
viewMenu->addAction(m_dockslLabel->toggleViewAction());
viewMenu->addAction(m_dockPixInfo->toggleViewAction());
connect(m_treeView,&LQTreeView::doubleClicked,this,[this](const QModelIndex index){
auto fileModel = static_cast<LQTreeView*>(sender())->fileModel();
if (!fileModel || !fileModel->isDir(index)) return;
golbalState.editPath = fileModel->filePath(index);
m_listView->slot_loadImagesFromDirectory(golbalState.editPath);
//qDebug()<<golbalState.editPath;
m_workPathShow->setText(golbalState.editPath);
});
connect(m_listView,&LQListView::signal_itemSelectChange,this,&MainWindow::slot_act_editPixMap);
connect(m_listWidgeLabels,&QListWidget::currentItemChanged,this,[this](QListWidgetItem *item){
if(item==nullptr) return;
if(!m_mapItemInfo.contains(item->text())) return;
auto itemRect = m_mapItemInfo[item->text()];
QList<QGraphicsItem *> sitems = m_sence->selectedItems();
for(int i=0;i!=sitems.size();i++)
{
if(sitems[i]->type() == LQGraphicsRectItem::Type || sitems[i]->type() == LQGraphicsPathItem::Type)
{
QGraphicsItem *rectItem = static_cast<QGraphicsItem*>(sitems[i]);
rectItem->setSelected(false);
}
}
itemRect->setSelected(true);
});
m_labelMouse = new QLabel();
QString strShow = QString("X: %1pix Y: %2pix").arg(0, 4, 10, QChar('0'))
.arg(0, 4, 10, QChar('0'));
m_labelMouse->setText(strShow);
m_workPathShow = new QLabel();
m_workPathShow->setTextInteractionFlags(Qt::TextSelectableByMouse);
statusBar()->addPermanentWidget(m_workPathShow);
statusBar()->addPermanentWidget(m_labelMouse);
connect(m_sence, &LQGraphicsScene::signal_sendPosition, this, &MainWindow::slot_postion);
connect(m_listView, &LQListView::customContextMenuRequested,this,[this](const QPoint &pos){
QPoint globalPos = m_listView->viewport()->mapToGlobal(pos);
manageMenu->exec(globalPos);
});
QIcon appIcon(":/images/iPhotoDraw.ico"); // 图标路径,资源文件路径
setWindowIcon(appIcon);
setWindowTitle(tr("图片标注软件V1.06"));
showMaximized();
}
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
resizeDocks({m_dockFileTree, m_dockImageList}, {this->width()/8, this->width()*29/80}, Qt::Horizontal);
resizeDocks({m_dockslLabel, m_dockPixInfo}, {this->width()/8, this->width()/8}, Qt::Horizontal);
resizeDocks({m_dockslLabel, m_dockPixInfo}, {this->height()/5, this->height()*4/5}, Qt::Vertical);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
golbalState.writeSettingIni();
QMainWindow::closeEvent(event);
}
void MainWindow::createMenus()
{
// 创建菜单栏
QMenuBar *menuBar = this->menuBar();
// 文件菜单
fileMenu = menuBar->addMenu(tr("文件"));
QAction *act_openDirAction = new QAction(tr("打开目录"), this);
act_openDirAction->setObjectName("act_openDirAction");
fileMenu->addAction(act_openDirAction);
QAction *act_closeDirAction = new QAction(tr("关闭目录"), this);
act_closeDirAction->setObjectName("act_closeDirAction");
fileMenu->addAction(act_closeDirAction);
fileMenu->addSeparator();
QAction *act_exitAction = new QAction(tr("退出"), this);
act_exitAction->setObjectName("act_exitAction");
fileMenu->addAction(act_exitAction);
// 管理菜单
manageMenu = menuBar->addMenu(tr("管理"));
QAction *act_mkdir = new QAction(tr("创建目录"), this);
act_mkdir->setObjectName("act_mkdir");
act_mkdir->setShortcut(QKeySequence(Qt::ShiftModifier | Qt::Key_M));
manageMenu->addAction(act_mkdir);
QAction *act_mgdel = new QAction(tr("删除图片"), this);
act_mgdel->setObjectName("act_mgdel");
act_mgdel->setShortcut(QKeySequence(Qt::ShiftModifier | Qt::Key_D));
manageMenu->addAction(act_mgdel);
QAction *act_mgrename = new QAction(tr("重命名"), this);
act_mgrename->setObjectName("act_mgrename");
act_mgrename->setShortcut(QKeySequence(Qt::ShiftModifier |Qt::Key_N));
manageMenu->addAction(act_mgrename);
QAction *act_mgrotate90r = new QAction(tr("顺时针旋转90°"), this);
act_mgrotate90r->setObjectName("act_mgrotate90r");
act_mgrotate90r->setShortcut(QKeySequence(Qt::ShiftModifier |Qt::Key_R));
manageMenu->addAction(act_mgrotate90r);
QAction *act_mgrotate90l = new QAction(tr("逆时针旋转90°"), this);
act_mgrotate90l->setObjectName("act_mgrotate90l");
act_mgrotate90l->setShortcut(QKeySequence(Qt::ShiftModifier |Qt::Key_L));
manageMenu->addAction(act_mgrotate90l);
QAction *act_mgcopy = new QAction(tr("复制图片到"), this);
act_mgcopy->setObjectName("act_mgcopy");
act_mgcopy->setShortcut(QKeySequence(Qt::ShiftModifier |Qt::Key_C));
manageMenu->addAction(act_mgcopy);
QAction *act_mgmove = new QAction(tr("移动图片到"), this);
act_mgmove->setObjectName("act_mgmove");
act_mgmove->setShortcut(QKeySequence(Qt::ShiftModifier |Qt::Key_V));
manageMenu->addAction(act_mgmove);
QAction *act_mgcut = new QAction(tr("剪裁图片"), this);
act_mgcut->setObjectName("act_mgcut");
act_mgcut->setShortcut(QKeySequence(Qt::ShiftModifier |Qt::Key_U));
manageMenu->addAction(act_mgcut);
// 标注菜单
annotateMenu = menuBar->addMenu(tr("标注"));
// 添加互斥单选菜单项(一组中只能选一个)
QActionGroup* radioGroup = new QActionGroup(annotateMenu);
radioGroup->setExclusive(true);
QAction* act_rect = new QAction(tr("矩形标注"), radioGroup);
act_rect->setObjectName("act_rect");
act_rect->setShortcut(QKeySequence(Qt::Key_F5));
act_rect->setCheckable(true);
QAction* act_polygon = new QAction(tr("多边形标注"), radioGroup);
act_polygon->setObjectName("act_polygon");
act_polygon->setShortcut(QKeySequence(Qt::Key_F6));
act_polygon->setCheckable(true);
if(golbalState.labelMode==0)
act_rect->setChecked(true);
else
act_polygon->setChecked(true);
annotateMenu->addActions(radioGroup->actions());
annotateMenu->addSeparator();
QAction *act_rectRoateR2 = new QAction(tr("矩形右旋"), this);
act_rectRoateR2->setObjectName("act_rectRoateR2");
act_rectRoateR2->setShortcut(QKeySequence(Qt::Key_R));
annotateMenu->addAction(act_rectRoateR2);
QAction *act_rectRoateL2 = new QAction(tr("矩形左旋"), this);
act_rectRoateL2->setObjectName("act_rectRoateL2");
act_rectRoateL2->setShortcut(QKeySequence(Qt::Key_Tab));
annotateMenu->addAction(act_rectRoateL2);
QAction *act_rectRoateR01 = new QAction(tr("矩形右旋微调"), this);
act_rectRoateR01->setObjectName("act_rectRoateR01");
act_rectRoateR01->setShortcut(QKeySequence(Qt::Key_E));
annotateMenu->addAction(act_rectRoateR01);
QAction *act_rectRoateL01 = new QAction(tr("矩形左旋微调"), this);
act_rectRoateL01->setObjectName("act_rectRoateL01");
act_rectRoateL01->setShortcut(QKeySequence(Qt::Key_Q));
annotateMenu->addAction(act_rectRoateL01);
QAction *act_rectWidthAdd = new QAction(tr("矩形宽度增加"), this);
act_rectWidthAdd->setObjectName("act_rectWidthAdd");
act_rectWidthAdd->setShortcut(QKeySequence(Qt::Key_D));
annotateMenu->addAction(act_rectWidthAdd);
QAction *act_rectWidthSub = new QAction(tr("矩形宽度减小"), this);
act_rectWidthSub->setObjectName("act_rectWidthSub");
act_rectWidthSub->setShortcut(QKeySequence(Qt::Key_A));
annotateMenu->addAction(act_rectWidthSub);
QAction *act_rectHeightAdd = new QAction(tr("矩形高度增加"), this);
act_rectHeightAdd->setObjectName("act_rectHeightAdd");
act_rectHeightAdd->setShortcut(QKeySequence(Qt::Key_W));
annotateMenu->addAction(act_rectHeightAdd);
QAction *act_rectHeightSub = new QAction(tr("矩形高度减小"), this);
act_rectHeightSub->setObjectName("act_rectHeightSub");
act_rectHeightSub->setShortcut(QKeySequence(Qt::Key_S));
annotateMenu->addAction(act_rectHeightSub);
QAction *act_rectCopy = new QAction(tr("复制矩形"), this);
act_rectCopy->setObjectName("act_rectCopy");
act_rectCopy->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_C));
annotateMenu->addAction(act_rectCopy);
QAction *act_rectPaste = new QAction(tr("粘贴矩形"), this);
act_rectPaste->setObjectName("act_rectPaste");
act_rectPaste->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_V));
annotateMenu->addAction(act_rectPaste);
annotateMenu->addSeparator();
QAction *act_selectClass = new QAction(tr("修改图元类别"), this);
act_selectClass->setObjectName("act_selectClass");
act_selectClass->setShortcut(QKeySequence(Qt::Key_T));
annotateMenu->addAction(act_selectClass);
QAction *act_addEll = new QAction(tr("多边形点添加"), this);
act_addEll->setObjectName("act_addEll");
act_addEll->setShortcut(QKeySequence(Qt::Key_B));
annotateMenu->addAction(act_addEll);
QAction *act_deleteItem = new QAction(tr("图元删除"), this);
act_deleteItem->setObjectName("act_deleteItem");
act_deleteItem->setShortcut(QKeySequence(Qt::Key_X));
annotateMenu->addAction(act_deleteItem);
QAction *act_setting = new QAction(tr("参数设置"), this);
act_setting->setObjectName("act_setting");
act_setting->setShortcut(QKeySequence(Qt::Key_P));
annotateMenu->addAction(act_setting);
QAction *act_viewZoonIn = new QAction(tr("视图缩小"), this);
act_viewZoonIn->setObjectName("act_viewZoonIn");
act_viewZoonIn->setShortcut(QKeySequence(Qt::Key_Minus));
annotateMenu->addAction(act_viewZoonIn);
QAction *act_viewZoonOut = new QAction(tr("视图放大"), this);
act_viewZoonOut->setObjectName("act_viewZoonOut");
act_viewZoonOut->setShortcut(QKeySequence(Qt::Key_Plus));
annotateMenu->addAction(act_viewZoonOut);
QAction *act_saveLableInfo = new QAction(tr("保存标注信息"), this);
act_saveLableInfo->setObjectName("act_saveLableInfo");
act_saveLableInfo->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_S));
annotateMenu->addAction(act_saveLableInfo);
QAction *act_prevPix = new QAction(tr("上一张"), this);
act_prevPix->setObjectName("act_prevPix");
act_prevPix->setShortcut(QKeySequence(Qt::Key_F1));
annotateMenu->addAction(act_prevPix);
QAction *act_nextPix = new QAction(tr("下一张"), this);
act_nextPix->setObjectName("act_nextPix");
act_nextPix->setShortcut(QKeySequence(Qt::Key_F2));
annotateMenu->addAction(act_nextPix);
annotateMenu->addSeparator();
// 导出菜单
exportMenu = menuBar->addMenu(tr("导出"));
QAction *act_dataCOCO = new QAction(tr("导出COCO格式数据"), this);
act_dataCOCO->setObjectName("act_dataCOCO");
exportMenu->addAction(act_dataCOCO);
act_dataCOCO->setVisible(false);
QAction *act_dataVOC = new QAction(tr("导出VOC格式数据"), this);
act_dataVOC->setObjectName("act_dataVOC");
exportMenu->addAction(act_dataVOC);
QAction *act_dataYOLO = new QAction(tr("导出YOLO格式数据"), this);
act_dataYOLO->setObjectName("act_dataYOLO");
exportMenu->addAction(act_dataYOLO);
// 视图菜单
viewMenu = menuBar->addMenu(tr("视图"));
// 添加互斥单选菜单项(一组中只能选一个)
QActionGroup* radioGroup1 = new QActionGroup(viewMenu);
radioGroup1->setExclusive(true);
QAction* act_modeMange = new QAction(tr("管理模式"), radioGroup1);
act_modeMange->setObjectName("act_modeMange");
act_modeMange->setShortcut(QKeySequence(Qt::Key_F3));
act_modeMange->setCheckable(true);
QAction* act_modeLabel = new QAction(tr("标注模式"), radioGroup1);
act_modeLabel->setObjectName("act_modeLabel");
act_modeLabel->setShortcut(QKeySequence(Qt::Key_F4));
act_modeLabel->setCheckable(true);
act_modeMange->setChecked(true);
viewMenu->addActions(radioGroup1->actions());
viewMenu->addSeparator();
// 脚本菜单
// scriptMenu = menuBar->addMenu(tr("python脚本"));
// QAction *act_testScript = new QAction(tr("测试脚本"), this);
// act_testScript->setObjectName("act_testScript");
// scriptMenu->addAction(act_testScript);
// 工具菜单 - 用于管理工具栏显示
QMenu *toolsMenu = menuBar->addMenu(tr("工具"));
// 帮助菜单
helpMenu = menuBar->addMenu(tr("其他"));
QActionGroup* radioGroupTheme = new QActionGroup(helpMenu);
radioGroupTheme->setExclusive(true);
QAction *act_themeDark = new QAction(tr("黑色主题"), radioGroupTheme);
act_themeDark->setObjectName("act_themeDark");
act_themeDark->setCheckable(true);
QAction *act_themeWhite = new QAction(tr("白色主题"), radioGroupTheme);
act_themeWhite->setObjectName("act_themeWhite");
act_themeWhite->setCheckable(true);
connect(act_themeDark, &QAction::triggered, this, [this](){
golbalState.themeStr = "dark";
slot_changeTheme(golbalState.themeStr);
});
connect(act_themeWhite, &QAction::triggered, this, [this](){
golbalState.themeStr = "white";
slot_changeTheme(golbalState.themeStr);
});
if(golbalState.themeStr=="dark")
act_themeDark->setChecked(true);
else
act_themeWhite->setChecked(true);
helpMenu->addActions(radioGroupTheme->actions());
helpMenu->addSeparator();
QActionGroup* radioGroupLang = new QActionGroup(helpMenu);
radioGroupLang->setExclusive(true);
QAction *act_langCN = new QAction("中文(需要重启)", radioGroupLang);
act_langCN->setObjectName("act_langCN");
act_langCN->setCheckable(true);
QAction *act_langEN = new QAction("English(Restart to apply)", radioGroupLang);
act_langEN->setObjectName("act_langEN");
act_langEN->setCheckable(true);
connect(act_langCN, &QAction::triggered, this, [this](){
golbalState.langStr = "zh";
slot_changeLang(golbalState.langStr);
});
connect(act_langEN, &QAction::triggered, this, [this](){
golbalState.langStr = "en";
slot_changeLang(golbalState.langStr);
});
if(golbalState.langStr=="zh")
act_langCN->setChecked(true);
else
act_langEN->setChecked(true);
helpMenu->addActions(radioGroupLang->actions());
helpMenu->addSeparator();
QAction *act_keyHelp = new QAction(tr("快捷键帮助"), this);
act_keyHelp->setObjectName("act_keyHelp");
helpMenu->addAction(act_keyHelp);
// 连接动作信号到槽函数
// 文件
connect(act_openDirAction, &QAction::triggered, this, &MainWindow::slot_act_openDirectory);
connect(act_closeDirAction, &QAction::triggered, this, &MainWindow::slot_act_closeDirectory);
connect(act_exitAction, &QAction::triggered, this, &MainWindow::close);
// 管理
connect(act_mkdir, &QAction::triggered, this, &MainWindow::slot_act_manage_mkdir);
connect(act_mgdel, &QAction::triggered, this, &MainWindow::slot_act_manage_delete);
connect(act_mgrename, &QAction::triggered, this, &MainWindow::slot_act_manage_rename);
connect(act_mgrotate90r, &QAction::triggered, this, &MainWindow::slot_act_manage_rotate90r);
connect(act_mgrotate90l, &QAction::triggered, this, &MainWindow::slot_act_rotate90l);
connect(act_mgcopy, &QAction::triggered, this, &MainWindow::slot_act_manage_copy);
connect(act_mgmove, &QAction::triggered, this, &MainWindow::slot_act_manage_move);
connect(act_mgcut, &QAction::triggered, this, &MainWindow::slot_act_manage_cut);
// 标注
connect(act_rect, &QAction::triggered, this, &MainWindow::slot_act_rect);
connect(act_polygon, &QAction::triggered, this, &MainWindow::slot_act_polygon);
connect(act_setting, &QAction::triggered, this, &MainWindow::slot_act_setting);
connect(act_rectRoateR2, &QAction::triggered, this, &MainWindow::slot_act_rectRoateR2);
connect(act_rectRoateL2, &QAction::triggered, this, &MainWindow::slot_act_rectRoateL2);
connect(act_rectRoateR01, &QAction::triggered, this, &MainWindow::slot_act_rectRoateR01);
connect(act_rectRoateL01, &QAction::triggered, this, &MainWindow::slot_act_rectRoateL01);
connect(act_rectWidthAdd, &QAction::triggered, this, &MainWindow::slot_act_rectWidthAdd);
connect(act_rectWidthSub, &QAction::triggered, this, &MainWindow::slot_act_rectWidthSub);
connect(act_rectHeightAdd, &QAction::triggered, this, &MainWindow::slot_act_rectHeightAdd);
connect(act_rectHeightSub, &QAction::triggered, this, &MainWindow::slot_act_rectHeightSub);
connect(act_rectCopy, &QAction::triggered, this, &MainWindow::slot_act_rectCopy);
connect(act_rectPaste, &QAction::triggered, this, &MainWindow::slot_act_rectPaste);
connect(act_selectClass, &QAction::triggered, this, &MainWindow::slot_act_selectClass);
connect(act_viewZoonIn, &QAction::triggered, this, &MainWindow::slot_act_viewZoonIn);
connect(act_viewZoonOut, &QAction::triggered, this, &MainWindow::slot_act_viewZoonOut);
connect(act_deleteItem, &QAction::triggered, this, &MainWindow::slot_act_deleteItem);
connect(act_saveLableInfo, &QAction::triggered, this, &MainWindow::slot_act_saveLableInfo);
connect(act_prevPix, &QAction::triggered, this, &MainWindow::slot_act_prevPix);
connect(act_nextPix, &QAction::triggered, this, &MainWindow::slot_act_nextPix);
connect(act_addEll, &QAction::triggered, this, &MainWindow::slot_act_addEll);
// 视图
connect(act_modeMange, &QAction::triggered, this, &MainWindow::slot_act_modeMange);
connect(act_modeLabel, &QAction::triggered, this, &MainWindow::slot_act_modeLabel);
//数据导出
connect(act_dataCOCO, &QAction::triggered, this, &MainWindow::slot_act_dataCOCO);
connect(act_dataVOC, &QAction::triggered, this, &MainWindow::slot_act_dataVOC);
connect(act_dataYOLO, &QAction::triggered, this, &MainWindow::slot_act_dataYOLO);
// 帮助
connect(act_keyHelp, &QAction::triggered, this,[](){
QLabel *label = new QLabel(tr("1、矩形绘图中,ALT和鼠标移动块快速调整大小。\n"
"2、多边形绘图中,快捷键B可以添加折线点。"));
label->show();
});
// 创建工具栏显示/隐藏的动作
toolBarActions = new QActionGroup(this);
toolBarActions->setExclusive(false);
QAction *showFileToolBar = new QAction(tr("文件工具栏"), this);
showFileToolBar->setObjectName("act_showFileToolBar");
showFileToolBar->setCheckable(true);
showFileToolBar->setChecked(true);
toolBarActions->addAction(showFileToolBar);
QAction *showManageToolBar = new QAction(tr("管理工具栏"), this);
showManageToolBar->setObjectName("act_showManageToolBar");
showManageToolBar->setCheckable(true);
showManageToolBar->setChecked(true);
toolBarActions->addAction(showManageToolBar);
QAction *showAnnotateToolBar = new QAction(tr("标注工具栏"), this);
showAnnotateToolBar->setObjectName("act_showAnnotateToolBar");
showAnnotateToolBar->setCheckable(true);
showAnnotateToolBar->setChecked(true);
toolBarActions->addAction(showAnnotateToolBar);
QAction *showViewToolBar = new QAction(tr("视图工具栏"), this);
showViewToolBar->setObjectName("act_showViewToolBar");
showViewToolBar->setCheckable(true);
showViewToolBar->setChecked(true);
toolBarActions->addAction(showViewToolBar);
QAction *showExportToolBar = new QAction(tr("导出工具栏"), this);
showExportToolBar->setObjectName("act_showExportToolBar");
showExportToolBar->setCheckable(true);
showExportToolBar->setChecked(true);
toolBarActions->addAction(showExportToolBar);
// QAction *showScriptToolBar = new QAction(tr("脚本工具栏"), this);
// showScriptToolBar->setObjectName("act_showScriptToolBar");
// showScriptToolBar->setCheckable(true);
// showScriptToolBar->setChecked(true);
// toolBarActions->addAction(showScriptToolBar);
// 添加到工具菜单
toolsMenu->addActions(toolBarActions->actions());
// 连接信号槽
connect(showFileToolBar, &QAction::toggled, this, [this](bool visible){
fileToolBar->setVisible(visible);
});
connect(showManageToolBar, &QAction::toggled, this, [this](bool visible){
manageToolBar->setVisible(visible);
});
connect(showAnnotateToolBar, &QAction::toggled, this, [this](bool visible){
annotateToolBar->setVisible(visible);
});
connect(showViewToolBar, &QAction::toggled, this, [this](bool visible){
viewToolBar->setVisible(visible);
});
connect(showExportToolBar, &QAction::toggled, this, [this](bool visible){
exportToolBar->setVisible(visible);
});
// connect(showScriptToolBar, &QAction::toggled, this, [this](bool visible){
// scriptToolBar->setVisible(visible);
// });
}
void MainWindow::createToolBars()
{
fileToolBar = new QToolBar;
manageToolBar = new QToolBar;
annotateToolBar= new QToolBar;
viewToolBar = new QToolBar;
exportToolBar = new QToolBar;
scriptToolBar = new QToolBar;
// 文件操作工具栏
fileToolBar = addToolBar(tr("文件"));
fileToolBar->setObjectName("FileToolBar");
fileToolBar->addAction(findChild<QAction*>("act_openDirAction"));
fileToolBar->addAction(findChild<QAction*>("act_closeDirAction"));
fileToolBar->addSeparator();
fileToolBar->addAction(findChild<QAction*>("act_exitAction"));
// 图片管理工具栏
manageToolBar = addToolBar(tr("管理"));
manageToolBar->setObjectName("ManageToolBar");
manageToolBar->addAction(findChild<QAction*>("act_mkdir"));
manageToolBar->addAction(findChild<QAction*>("act_mgdel"));
manageToolBar->addAction(findChild<QAction*>("act_mgrename"));
manageToolBar->addSeparator();
manageToolBar->addAction(findChild<QAction*>("act_mgrotate90r"));
manageToolBar->addAction(findChild<QAction*>("act_mgrotate90l"));
manageToolBar->addSeparator();
manageToolBar->addAction(findChild<QAction*>("act_mgcopy"));
manageToolBar->addAction(findChild<QAction*>("act_mgmove"));
manageToolBar->addSeparator();
manageToolBar->addAction(findChild<QAction*>("act_mgcut"));
// 标注工具栏
annotateToolBar = addToolBar(tr("标注"));
annotateToolBar->setObjectName("AnnotateToolBar");
// 标注模式按钮组
annotateToolBar->addAction(findChild<QAction*>("act_rect"));
annotateToolBar->addAction(findChild<QAction*>("act_polygon"));
annotateToolBar->addSeparator();
annotateToolBar->addAction(findChild<QAction*>("act_rectRoateR2"));
annotateToolBar->addAction(findChild<QAction*>("act_rectRoateL2"));
annotateToolBar->addAction(findChild<QAction*>("act_rectRoateR01"));
annotateToolBar->addAction(findChild<QAction*>("act_rectRoateL01"));
annotateToolBar->addSeparator();
annotateToolBar->addAction(findChild<QAction*>("act_rectWidthAdd"));
annotateToolBar->addAction(findChild<QAction*>("act_rectWidthSub"));
annotateToolBar->addAction(findChild<QAction*>("act_rectHeightAdd"));
annotateToolBar->addAction(findChild<QAction*>("act_rectHeightSub"));
annotateToolBar->addSeparator();
annotateToolBar->addAction(findChild<QAction*>("act_rectCopy"));
annotateToolBar->addAction(findChild<QAction*>("act_rectPaste"));
annotateToolBar->addSeparator();
annotateToolBar->addAction(findChild<QAction*>("act_selectClass"));
annotateToolBar->addAction(findChild<QAction*>("act_addEll"));
annotateToolBar->addAction(findChild<QAction*>("act_deleteItem"));
annotateToolBar->addSeparator();
annotateToolBar->addAction(findChild<QAction*>("act_setting"));
annotateToolBar->addAction(findChild<QAction*>("act_saveLableInfo"));
annotateToolBar->addSeparator();
annotateToolBar->addAction(findChild<QAction*>("act_viewZoonIn"));
annotateToolBar->addAction(findChild<QAction*>("act_viewZoonOut"));
annotateToolBar->addSeparator();
annotateToolBar->addAction(findChild<QAction*>("act_prevPix"));
annotateToolBar->addAction(findChild<QAction*>("act_nextPix"));
// 视图操作工具栏
viewToolBar = addToolBar(tr("视图"));
viewToolBar->setObjectName("ViewToolBar");
viewToolBar->addAction(findChild<QAction*>("act_modeMange"));
viewToolBar->addAction(findChild<QAction*>("act_modeLabel"));
// 导出工具栏
exportToolBar = addToolBar(tr("导出"));
exportToolBar->setObjectName("ExportToolBar");
exportToolBar->addAction(findChild<QAction*>("act_dataCOCO"));
exportToolBar->addAction(findChild<QAction*>("act_dataVOC"));
exportToolBar->addAction(findChild<QAction*>("act_dataYOLO"));
// // 脚本工具栏
// scriptToolBar = addToolBar(tr("python脚本"));
// scriptToolBar->setObjectName("ScriptToolBar");
// scriptToolBar->addAction(findChild<QAction*>("act_testScript"));
// 设置工具栏图标和工具提示
setupToolBarIcons();
}
void MainWindow::setupToolBarIcons()
{
// 文件工具栏图标
findChild<QAction*>("act_openDirAction")->setIcon(QIcon(":/icons/open_folder.png"));
findChild<QAction*>("act_closeDirAction")->setIcon(QIcon(":/icons/close_folder.png"));
findChild<QAction*>("act_exitAction")->setIcon(QIcon(":/icons/exit.png"));
// 管理工具栏图标
findChild<QAction*>("act_mkdir")->setIcon(QIcon(":/icons/mkdir.png"));
findChild<QAction*>("act_mgdel")->setIcon(QIcon(":/icons/delete.png"));
findChild<QAction*>("act_mgrename")->setIcon(QIcon(":/icons/rename.png"));
findChild<QAction*>("act_mgrotate90r")->setIcon(QIcon(":/icons/image_rotate_right.png"));
findChild<QAction*>("act_mgrotate90l")->setIcon(QIcon(":/icons/image_rotate_left.png"));
findChild<QAction*>("act_mgcopy")->setIcon(QIcon(":/icons/copy.png"));
findChild<QAction*>("act_mgmove")->setIcon(QIcon(":/icons/move.png"));
findChild<QAction*>("act_mgcut")->setIcon(QIcon(":/icons/cut.png"));
// 标注工具栏图标
findChild<QAction*>("act_rect")->setIcon(QIcon(":/icons/rectangle.png"));
findChild<QAction*>("act_polygon")->setIcon(QIcon(":/icons/polygon.png"));
findChild<QAction*>("act_rectRoateR2")->setIcon(QIcon(":/icons/rotate_right.png"));
findChild<QAction*>("act_rectRoateL2")->setIcon(QIcon(":/icons/rotate_left.png"));
findChild<QAction*>("act_rectRoateR01")->setIcon(QIcon(":/icons/rotate_right_small.png"));
findChild<QAction*>("act_rectRoateL01")->setIcon(QIcon(":/icons/rotate_left_small.png"));
findChild<QAction*>("act_rectWidthAdd")->setIcon(QIcon(":/icons/width_increase.png"));
findChild<QAction*>("act_rectWidthSub")->setIcon(QIcon(":/icons/width_decrease.png"));
findChild<QAction*>("act_rectHeightAdd")->setIcon(QIcon(":/icons/height_increase.png"));
findChild<QAction*>("act_rectHeightSub")->setIcon(QIcon(":/icons/height_decrease.png"));
findChild<QAction*>("act_rectCopy")->setIcon(QIcon(":/icons/copy_rect.png"));
findChild<QAction*>("act_rectPaste")->setIcon(QIcon(":/icons/paste_rect.png"));
findChild<QAction*>("act_selectClass")->setIcon(QIcon(":/icons/select_class.png"));
findChild<QAction*>("act_addEll")->setIcon(QIcon(":/icons/add_point.png"));
findChild<QAction*>("act_deleteItem")->setIcon(QIcon(":/icons/delete_item.png"));
findChild<QAction*>("act_setting")->setIcon(QIcon(":/icons/settings.png"));
findChild<QAction*>("act_saveLableInfo")->setIcon(QIcon(":/icons/save.png"));
// 视图工具栏图标
findChild<QAction*>("act_modeMange")->setIcon(QIcon(":/icons/manage_mode.png"));
findChild<QAction*>("act_modeLabel")->setIcon(QIcon(":/icons/label_mode.png"));
findChild<QAction*>("act_viewZoonIn")->setIcon(QIcon(":/icons/zoom_out.png"));
findChild<QAction*>("act_viewZoonOut")->setIcon(QIcon(":/icons/zoom_in.png"));
findChild<QAction*>("act_prevPix")->setIcon(QIcon(":/icons/previous.png"));
findChild<QAction*>("act_nextPix")->setIcon(QIcon(":/icons/next.png"));
// 导出工具栏图标
findChild<QAction*>("act_dataCOCO")->setIcon(QIcon(":/icons/export_coco.png"));
findChild<QAction*>("act_dataVOC")->setIcon(QIcon(":/icons/export_voc.png"));
findChild<QAction*>("act_dataYOLO")->setIcon(QIcon(":/icons/export_yolo.png"));
// // 脚本工具栏图标
// findChild<QAction*>("act_testScript")->setIcon(QIcon(":/icons/script.png"));
// 设置所有工具栏按钮的工具提示(显示功能名称和快捷键)
QList<QAction*> allActions = findChildren<QAction*>();
foreach (QAction* action, allActions) {
if (!action->shortcut().isEmpty()) {
action->setToolTip(action->text() + " (" + action->shortcut().toString() + ")");
} else {
action->setToolTip(action->text());
}
}
#define ICO_SIZE 15
fileToolBar->setIconSize(QSize(ICO_SIZE, ICO_SIZE));
manageToolBar->setIconSize(QSize(ICO_SIZE, ICO_SIZE));
annotateToolBar->setIconSize(QSize(ICO_SIZE, ICO_SIZE));
viewToolBar->setIconSize(QSize(ICO_SIZE, ICO_SIZE));
exportToolBar->setIconSize(QSize(ICO_SIZE, ICO_SIZE));
scriptToolBar->setIconSize(QSize(ICO_SIZE, ICO_SIZE));
// fileToolBar->setMaximumHeight(15); // 最大宽度和高度
// manageToolBar->setMaximumHeight(15); // 最大宽度和高度
// annotateToolBar->setMaximumHeight(15); // 最大宽度和高度
// viewToolBar->setMaximumHeight(15); // 最大宽度和高度
// exportToolBar->setMaximumHeight(15); // 最大宽度和高度
// scriptToolBar->setMaximumHeight(15); // 最大宽度和高度
}
void MainWindow::restoreLastWorkPath()
{
CustomFileSystemModel *fmodel = static_cast<CustomFileSystemModel*>(m_treeView->model());
m_treeView->setRootIndex(fmodel->index(golbalState.workPath));
m_treeView->expand(fmodel->index(golbalState.editPath));
m_listView->slot_loadImagesFromDirectory(golbalState.editPath);
m_workPathShow->setText(golbalState.editPath);
QApplication::processEvents(QEventLoop::AllEvents,100);
QStandardItemModel *modelX = static_cast<QStandardItemModel*>(m_listView->model()) ;
QApplication::processEvents(QEventLoop::AllEvents,100);
if(modelX->rowCount()>0){
m_listView->setCurrentIndex(modelX->index(0,0));
}
}
void MainWindow::slot_act_openDirectory()
{
// 1. 让用户选择目标目录
QString targetDir = QFileDialog::getExistingDirectory(
nullptr,
tr("选择目标目录"),
QDir::homePath()
);
if (targetDir.isEmpty()) {
QMessageBox::information(nullptr, tr("提示"), tr("未选择目录,操作已取消"));
return;
}
CustomFileSystemModel *fmodel = static_cast<CustomFileSystemModel*>(m_treeView->model());
m_treeView->setRootIndex(fmodel->index(targetDir));
golbalState.workPath = targetDir;
golbalState.editPath = targetDir;
m_listView->slot_loadImagesFromDirectory(targetDir);
m_workPathShow->setText(golbalState.editPath);
}
void MainWindow::slot_act_closeDirectory()
{
CustomFileSystemModel *fmodel = static_cast<CustomFileSystemModel*>(m_treeView->model());
m_treeView->setRootIndex(fmodel->index(""));
}
void MainWindow::slot_act_manage_mkdir()
{
QString basePath = golbalState.editPath;
// 1. 获取用户输入的新文件夹名称
bool ok;
QString folderName = QInputDialog::getText(nullptr,
"创建新文件夹",
"请输入文件夹名称:",
QLineEdit::Normal,
"",
&ok);
// 用户点击取消
if (!ok || folderName.isEmpty()) {
return ;
}
// 2. 构造完整路径
QDir baseDir(basePath);
QString fullPath = baseDir.filePath(folderName);
// 3. 尝试创建目录
if (baseDir.mkdir(folderName)) {
statusBar()->showMessage(QString(tr("文件夹创建成功:\n%1")).arg(fullPath));
} else {
statusBar()->showMessage(QString(tr("无法创建文件夹:\n%1")).arg(fullPath));
}
}
void MainWindow::slot_act_manage_delete()
{
// 获取所有选中的索引
QModelIndexList selectedIndexes = m_listView->selectionModel()->selectedIndexes();
// 提取选中项的数据
QStringList selectedItems;
for (const QModelIndex &index : selectedIndexes) {
if (index.isValid()) {
selectedItems << index.data(Qt::UserRole+1).toString(); // 获取显示文本
}
}
// 提取行号并去重
QList<int> rows;
for (const QModelIndex &index : selectedIndexes) {
if (index.isValid()) {
int row = index.row();
if (!rows.contains(row)) {
rows.append(row);
}
}
}
// 按逆序排序(从大到小)
std::sort(rows.begin(), rows.end(), std::greater<int>());
// 删除行
for (int row : rows) {
m_listView->model()->removeRow(row); // QStandardItemModel 直接删除行
}
// 创建进度条对话框
QProgressDialog progressDialog;
progressDialog.setWindowTitle(tr("处理进度"));
progressDialog.setLabelText(tr("正在批量处理图片..."));
progressDialog.setCancelButton(nullptr);
progressDialog.setRange(0, selectedIndexes.size());
progressDialog.setModal(true); // 设置为模态对话框,阻塞用户其他操作
progressDialog.show();
int i=0;
//本地目录删除文件
for (const QString &filePath : selectedItems) {
QFileInfo fileInfo(filePath);
QString pathName = fileInfo.path() + "/" + fileInfo.baseName() + ".path";
QFile::remove(filePath);
QFile::remove(pathName);
progressDialog.setValue(i);
progressDialog.setLabelText(QString(tr("正在处理:%1/%2")).arg(i+1).arg(selectedIndexes.size()));
QApplication::processEvents();
i++;
}
progressDialog.setValue(selectedIndexes.size());
}
void MainWindow::slot_act_manage_rename()
{
// 获取所有选中的索引
QModelIndexList selectedIndexes = m_listView->selectionModel()->selectedIndexes();
if(selectedIndexes.size()==0) return;
QDialog dialog;
QFormLayout *formLay = new QFormLayout;
QLineEdit *lineEdit = new QLineEdit("#####");
QSpinBox *spinbox = new QSpinBox;spinbox->setRange(1,1000000);
QPushButton *bt = new QPushButton(tr("确定"));
formLay->addRow(tr("命名格式"),lineEdit);
formLay->addRow(tr("起始序号"),spinbox);
formLay->addRow(bt);
dialog.setLayout(formLay);
connect(bt,&QPushButton::clicked,&dialog,&QDialog::accept);
if(dialog.exec() != QDialog::Accepted) return;
QString fomatStr = lineEdit->text();
int wdnum = fomatStr.count("#");
int startnum = spinbox->value();
QStringList psstr = fomatStr.split(".");
QString preStr="";
QString surStr="";
if(psstr.size()>=1) preStr = psstr[0];
if(psstr.size()>=2) surStr = psstr[1];
preStr = preStr.replace("#","");
// 提取选中项的数据
// 创建进度条对话框
QProgressDialog progressDialog;
progressDialog.setWindowTitle(tr("处理进度"));
progressDialog.setLabelText(tr("正在批量处理图片..."));
progressDialog.setCancelButton(nullptr);
progressDialog.setRange(0, selectedIndexes.size());
progressDialog.setModal(true); // 设置为模态对话框,阻塞用户其他操作
progressDialog.show();
int i=0;
for (const QModelIndex &index : selectedIndexes) {
if (index.isValid()) {
QString oldFileName = index.data(Qt::UserRole+1).toString(); // 旧文件名称
QFileInfo fileInfo(oldFileName);
QString newBaseName = QString("%1").arg(startnum, wdnum, 10, QChar('0'));
QString dotName = surStr.isEmpty()?fileInfo.suffix():surStr;
newBaseName = preStr + newBaseName + "." + dotName;
QString newFileName = fileInfo.path() + "/" + newBaseName;
// 重命名文件
if (QFile::rename(oldFileName, newFileName)) {
// 更新模型的 UserRole+1 数据
m_listView->model()->setData(index, newFileName, Qt::UserRole + 1);
m_listView->model()->setData(index, newBaseName, Qt::DisplayRole);
QFileInfo fileInfo(oldFileName);
QString oldPathName = fileInfo.path() + "/" + fileInfo.completeBaseName() + ".path";
QFileInfo fileInfo1(newFileName);
QString newPathName = fileInfo1.path() + "/" +fileInfo1.completeBaseName() + ".path";
//qDebug()<<oldPathName<<newPathName;
QFile::rename(oldPathName, newPathName);
startnum++;
}
progressDialog.setValue(i);
progressDialog.setLabelText(QString(tr("正在处理:%1/%2")).arg(i+1).arg(selectedIndexes.size()));
QApplication::processEvents();
i++;
}
}
progressDialog.setValue(selectedIndexes.size());
}
void MainWindow::slot_act_manage_rotate90r()
{
fun_rotate_select_image(90);
}