DialogMeshRename.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "DialogMeshRename.h"
  2. #include "ui_DialogGeometryRename.h"
  3. #include "MeshData/meshSingleton.h"
  4. #include "MeshData/meshKernal.h"
  5. #include "MeshData/meshSet.h"
  6. #include "MainWindow/MainWindow.h"
  7. #include "DataProperty/DataBase.h"
  8. #include <QMessageBox>
  9. #include <QTreeWidgetItem>
  10. namespace MainWidget
  11. {
  12. MeshRenameDialog::MeshRenameDialog(GUI::MainWindow *mw, QTreeWidgetItem *item)
  13. : QFDialog(mw), _item(item)
  14. {
  15. _ui = new Ui::DialogRename;
  16. _ui->setupUi(this);
  17. _meshdata = MeshData::MeshData::getInstance();
  18. _type = (TreeItemType)item->type();
  19. int id = item->data(0, Qt::UserRole).toInt();
  20. if (_type == MeshChild)
  21. _data = _meshdata->getKernalByID(id);
  22. else
  23. _data = _meshdata->getMeshSetByID(id);
  24. QString name = _data->getName();
  25. _ui->newNamelineEdit->setText(name);
  26. connect(this, SIGNAL(disPlayProp(DataProperty::DataBase *)), mw, SIGNAL(updateProperty(DataProperty::DataBase *)));
  27. }
  28. MeshRenameDialog::~MeshRenameDialog()
  29. {
  30. if (_ui == nullptr)
  31. delete _ui;
  32. }
  33. void MeshRenameDialog::accept()
  34. {
  35. QString strNew = _ui->newNamelineEdit->text();
  36. if (strNew.isEmpty() || _data == nullptr)
  37. return;
  38. QString strOld = _data->getName();
  39. if (strNew == strOld)
  40. {
  41. QMessageBox::warning(this, tr("Warning"), tr("The Same Name!"));
  42. return;
  43. }
  44. else
  45. {
  46. _data->setName(strNew);
  47. _item->setText(0, strNew);
  48. }
  49. emit disPlayProp(_data);
  50. QDialog::accept();
  51. }
  52. }