FreeCAD

Форк
0
/
DlgPageChooser.cpp 
102 строки · 3.6 Кб
1
/****************************************************************************
2
 *   Copyright (c) 2021 Wanderer Fan <wandererfan@gmail.com>                *
3
 *                                                                          *
4
 *   This file is part of the FreeCAD CAx development system.               *
5
 *                                                                          *
6
 *   This library is free software; you can redistribute it and/or          *
7
 *   modify it under the terms of the GNU Library General Public            *
8
 *   License as published by the Free Software Foundation; either           *
9
 *   version 2 of the License, or (at your option) any later version.       *
10
 *                                                                          *
11
 *   This library  is distributed in the hope that it will be useful,       *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
14
 *   GNU Library General Public License for more details.                   *
15
 *                                                                          *
16
 *   You should have received a copy of the GNU Library General Public      *
17
 *   License along with this library; see the file COPYING.LIB. If not,     *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,          *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                 *
20
 *                                                                          *
21
 ****************************************************************************/
22

23
#include "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <QListWidgetItem>
26
# include <QList>
27
#endif
28

29
#include <Base/Console.h> // for FC_LOG_LEVEL_INIT
30
#include <Base/Tools.h>
31

32
#include "DlgPageChooser.h"
33
#include "ui_DlgPageChooser.h"
34

35

36
FC_LOG_LEVEL_INIT("Gui", true, true)
37

38
using namespace TechDrawGui;
39

40
/* TRANSLATOR Gui::DlgPageChooser */
41

42
DlgPageChooser::DlgPageChooser(
43
        const std::vector<std::string> labels,
44
        const std::vector<std::string> names,
45
        QWidget* parent, Qt::WindowFlags fl)
46
  : QDialog(parent, fl), ui(new Ui_DlgPageChooser)
47
{
48
    ui->setupUi(this);
49
    ui->lwPages->setSortingEnabled(true);
50

51
    fillList(labels, names);
52

53
    connect(ui->bbButtons, &QDialogButtonBox::accepted, this, &QDialog::accept);
54
    connect(ui->bbButtons, &QDialogButtonBox::rejected, this, &QDialog::reject);
55
}
56

57
/**
58
 *  Destroys the object and frees any allocated resources
59
 */
60
DlgPageChooser::~DlgPageChooser()
61
{
62
    // no need to delete child widgets, Qt does it all for us
63
    delete ui;
64
}
65

66
void DlgPageChooser::fillList(std::vector<std::string> labels, std::vector<std::string> names)
67
{
68
    QListWidgetItem* item;
69
    QString qLabel;
70
    QString qName;
71
    QString qText;
72
    int labelCount = labels.size();
73
    int i = 0;
74
    for (; i < labelCount; i++) {
75
        qLabel = Base::Tools::fromStdString(labels[i]);
76
        qName = Base::Tools::fromStdString(names[i]);
77
        qText = QString::fromUtf8("%1 (%2)").arg(qLabel, qName);
78
        item = new QListWidgetItem(qText, ui->lwPages);
79
        item->setData(Qt::UserRole, qName);
80
    }
81
}
82

83
std::string DlgPageChooser::getSelection() const
84
{
85
    QList<QListWidgetItem*> sels = ui->lwPages->selectedItems();
86
    if (!sels.empty()) {
87
        QListWidgetItem* item = sels.front();
88
        return item->data(Qt::UserRole).toByteArray().constData();
89
    }
90
    return std::string();
91
}
92

93

94
void DlgPageChooser::accept() {
95
    QDialog::accept();
96
}
97

98
void DlgPageChooser::reject() {
99
    QDialog::reject();
100
}
101

102
#include "moc_DlgPageChooser.cpp"
103

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.