Seamly2D
Code documentation
addtogroup_dialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file addtogroup_dialog.cpp
3  ** @author Douglas S Caskey
4  ** @date Mar 14, 2023
5  **
6  ** @copyright
7  ** Copyright (C) 2023 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 #include "addtogroup_dialog.h"
26 #include "ui_addtogroup_dialog.h"
27 
28 #include "../ifc/ifcdef.h"
29 #include "../ifc/xml/vabstractpattern.h"
30 #include "../tools/dialogtool.h"
31 #include "../vmisc/vabstractapplication.h"
32 #include "../vmisc/vcommonsettings.h"
33 #include "../vpatterndb/vcontainer.h"
34 #include "../vtools/undocommands/addgroup.h"
35 
36 #include <QStringList>
37 #include <QComboBox>
38 
39 //---------------------------------------------------------------------------------------------------------------------
40 AddToGroupDialog::AddToGroupDialog(VContainer *data, const quint32 &toolId, QWidget *parent)
41  : DialogTool(data, toolId, parent)
42  , ui(new Ui::AddToGroupDialog)
43  , m_doc(qApp->getCurrentDocument())
44  , m_groupData()
45  , m_beep(new QSound(qApp->Settings()->getSelectionSound()))
46 {
47  ui->setupUi(this);
48  setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
49  setWindowIcon(QIcon(":/icon/32x32/group.png"));
50 
51  fillNameBox();
52 
54 }
55 
56 //---------------------------------------------------------------------------------------------------------------------
58 {
59  delete ui;
60 }
61 
62 //---------------------------------------------------------------------------------------------------------------------
64 {
66  QStringList groupNames;
67  auto i = groups.constBegin();
68  while (i != groups.constEnd())
69  {
70  const GroupAttributes data = i.value();
71  groupNames.append(data.name);
72  ++i;
73  }
74  ui->groupName_ComboBox->addItems(groupNames);
75 }
76 
77 //---------------------------------------------------------------------------------------------------------------------
79 {
80  return ui->groupName_ComboBox->currentText();
81 }
82 
83 
84 //---------------------------------------------------------------------------------------------------------------------
86 {
87  if (not click)
88  {
89  if (m_groupData.isEmpty())
90  {
91  return;
92  }
93 
94  setModal(true);
95  emit ToolTip("");
96  show();
97  }
98 }
99 
100 //---------------------------------------------------------------------------------------------------------------------
101 void AddToGroupDialog::SelectedObject(bool selected, quint32 object, quint32 tool)
102 {
103  if (selected)
104  {
105  m_groupData.insert(object, tool);
106  m_beep->play();
107  }
108  else
109  {
110  m_groupData.remove(object);
111  }
112 }
113 
114 //---------------------------------------------------------------------------------------------------------------------
116 {
117  return m_groupData;
118 }
VAbstractPattern * m_doc
virtual void ShowDialog(bool click) Q_DECL_OVERRIDE
virtual void SelectedObject(bool selected, quint32 object, quint32 tool) Q_DECL_OVERRIDE
QMap< quint32, quint32 > getGroupData() const
QString getName() const
QMap< quint32, quint32 > m_groupData
Ui::AddToGroupDialog * ui
AddToGroupDialog(VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
void ToolTip(const QString &toolTip)
ToolTip emit tooltipe for tool.
void initializeOkCancel(T *ui)
initializeOkCancel initialize OK and Cancel buttons
Definition: dialogtool.h:379
const VContainer * data
data container with data
Definition: dialogtool.h:177
QMap< quint32, GroupAttributes > getGroups()
The VContainer class container of all variables.
Definition: vcontainer.h:141
#define qApp
Definition: vapplication.h:67