Commit 3a8b62b6 authored by vladburin's avatar vladburin
Browse files

GUI Qt ClassesListWidget updated

--HG--
branch : RunTimeLibsTest
parent 32ef450a11e0
#include "UClassesListWidget.h"
#include "ui_UClassesListWidget.h"
#include "UDrawEngineWidget.h"
#include <QMimeData>
#include <QDragMoveEvent>
#include <QDrag>
......@@ -91,6 +91,7 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
UClassesListWidget::~UClassesListWidget()
{
delete ui;
}
QString UClassesListWidget::selctedClass() const
......@@ -259,7 +260,6 @@ void UClassesListWidget::tab2_textChanged(const QString &arg1)
ui->listWidgetRTlibs->clear();
// runtime-
// TODO Storage
auto storage = RDK::GetStorageLock();
std::string buff;
storage->GetRTlibsNameList(buff);
......@@ -328,49 +328,58 @@ void UClassesListWidget::DeleteRTlibrary()
{
//
if(ui->listWidgetRTlibs->selectedItems().size() == 0)
{
return;
}
QListWidgetItem* item = ui->listWidgetRTlibs->currentItem();
// Storage
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
//
QListWidgetItem* item = ui->listWidgetRTlibs->currentItem();
QString lib_name = item->text().toUtf8().data();
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
//
QString message = "Deleting library \""+ lib_name + "\"";
if(!storage)
return;
DeleteDialog* dialog = new DeleteDialog("Delete Library", message);
storage->DeleteRuntimeCollection(lib_name.toLocal8Bit().data());
if(dialog->exec() == QDialog::Accepted)
{
storage->DeleteRuntimeCollection(lib_name.toLocal8Bit().data());
AUpdateInterface();
}
delete dialog;
AUpdateInterface();
}
void UClassesListWidget::AddNewClass()
{
//
if(ui->listWidgetRTlibs->selectedItems().size() == 0)
{
return;
}
RDK::UELockPtr<RDK::UEngine> engine=RDK::GetEngineLock();
if(!engine)
//
if(!engine || !engine->GetModel())
return;
// ->
if(!engine->GetModel())
{
return;
}
// ( )
QString lib_name = "";
if(ui->listWidgetRTlibs->currentItem())
lib_name = ui->listWidgetRTlibs->currentItem()->text();
QString lib_name = ui->listWidgetRTlibs->currentItem()->text();
std::string buff;
engine->GetModel()->GetStorage()->GetRTlibsNameList(buff);
QStringList libs_names = QString(buff.c_str()).split(",");
CrClassDialog* dialog = new CrClassDialog(lib_name);
CrClassDialog* dialog = new CrClassDialog(libs_names,lib_name);
if(dialog->exec() == QDialog::Accepted)
{
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()->GetComponent(dialog->GetCompName(), true);
//
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()
->GetComponent(static_cast<UDrawEngineWidget*>(this->parentWidget()->parentWidget()->parentWidget())->GetSelectedCmponent(), true);
//
if(!container)
{
......@@ -391,25 +400,33 @@ void UClassesListWidget::DeleteClass()
{
//
if(ui->listWidgetRTlibs->selectedItems().empty() || ui->listWidgetRTlibClasses->selectedItems().empty())
{
return;
}
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
return;
//
QListWidgetItem* item = ui->listWidgetRTlibs->currentItem();
QString lib_name = item->text();
//
item = ui->listWidgetRTlibClasses->currentItem();
QString class_name = item->text();
//
storage->DelClassFromCollection(class_name.toUtf8().data(), lib_name.toUtf8().data());
//
QString message = "Deleting class \""+ class_name + "\" from library \"" + lib_name + "\"";
DeleteDialog* dialog = new DeleteDialog("Delete Class", message);
AUpdateInterface();
if(dialog->exec() == QDialog::Accepted)
{
storage->DelClassFromCollection(class_name.toUtf8().data(), lib_name.toUtf8().data());
AUpdateInterface();
}
delete dialog;
}
//
......@@ -419,15 +436,17 @@ CrLibDialog::CrLibDialog(QWidget* pwgt)
InputLibName = new QLineEdit;
Message = new QLabel("Enter library name");
QPushButton* ok_button = new QPushButton("Ok");
Message = new QLabel("Enter Library Name");
AddButton = new QPushButton("Ok");
AddButton->setEnabled(false);
QPushButton* cancel_button = new QPushButton("Cancel");
connect(ok_button,SIGNAL(clicked()),this,SLOT(ProcessInput()));
connect(cancel_button,SIGNAL(clicked()),SLOT(reject()));
connect(AddButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancel_button,SIGNAL(clicked()),this, SLOT(reject()));
connect(InputLibName,SIGNAL(textChanged(const QString &)),this,SLOT(ProcessInput()));
QHBoxLayout* hbox_layout = new QHBoxLayout;
hbox_layout->addWidget(ok_button);
hbox_layout->addWidget(AddButton);
hbox_layout->addWidget(cancel_button);
QVBoxLayout* vbox_layout = new QVBoxLayout;
......@@ -442,6 +461,8 @@ void CrLibDialog::ProcessInput()
//
if(InputLibName->text().isEmpty())
{
Message->setText("Enter Library Name");
AddButton->setEnabled(false);
return;
}
......@@ -450,13 +471,19 @@ void CrLibDialog::ProcessInput()
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
return;
//
if(!storage->GetCollection(lib_name))
accept(); // -
{
Message->setText("Enter library name");
AddButton->setEnabled(true);
}
else
{
AddButton->setEnabled(false);
Message->setText("Library with this name already exists");
}
}
......@@ -467,83 +494,89 @@ const std::string CrLibDialog::GetLibName() const
}
//
CrClassDialog::CrClassDialog(QString lib_name, QWidget* pwgt) :Replace(false)
CrClassDialog::CrClassDialog(QStringList libs, QString cur_lib, QWidget* pwgt)
{
setWindowTitle("Add New Class");
Info = new QLabel("Adding Class to \"" + lib_name + "\" library");
MessageClass = new QLabel("Enter Class name");
MessageLib = new QLabel("Select the library where to add the component");
// , ( )
Libraries = new QComboBox;
Libraries->addItems(libs);
int index = Libraries->findText(cur_lib);
if ( index != -1 ) { // -1
Libraries->setCurrentIndex(index);
}
MessageClass = new QLabel("Enter Class Name");
InputClassName = new QLineEdit;
MessageComp = new QLabel("Enter Comp name");
ComponentName = new QLineEdit;
QPushButton* ok_button = new QPushButton("Ok");
AddButton = new QPushButton("Add");
ReplaceButton = new QPushButton("Replace");
AddButton->setEnabled(false);
ReplaceButton->setEnabled(false);
QPushButton* cancel_button = new QPushButton("Cancel");
connect(ok_button,SIGNAL(clicked()),this,SLOT(ProcessInput()));
connect(cancel_button,SIGNAL(clicked()),SLOT(reject()));
connect(AddButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(ReplaceButton,SIGNAL(clicked()),this,SLOT(accept()));
connect(cancel_button,SIGNAL(clicked()),this, SLOT(reject()));
connect(InputClassName,SIGNAL(textChanged(const QString &)),this,SLOT(ProcessInput()));
QHBoxLayout* hbox_layout = new QHBoxLayout;
hbox_layout->addWidget(ok_button);
hbox_layout->addWidget(AddButton);
hbox_layout->addWidget(ReplaceButton);
hbox_layout->addWidget(cancel_button);
QVBoxLayout* vbox_layout = new QVBoxLayout;
vbox_layout->addWidget(Info);
vbox_layout->addWidget(MessageLib);
vbox_layout->addWidget(Libraries);
vbox_layout->addWidget(MessageClass);
vbox_layout->addWidget(InputClassName);
vbox_layout->addWidget(MessageComp);
vbox_layout->addWidget(ComponentName);
vbox_layout->addLayout(hbox_layout);
setLayout(vbox_layout);
}
void CrClassDialog::ProcessInput()
{
QString class_name = InputClassName->text();
//
if(class_name.isEmpty())
if(InputClassName->text().isEmpty())
{
MessageClass->setText("Enter Class Name");
AddButton->setEnabled(false);
ReplaceButton->setEnabled(false);
Replace = false;
return;
}
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
AddButton->setEnabled(false);
ReplaceButton->setEnabled(false);
Replace = false;
//
RDK::UELockPtr<RDK::UEngine> engine=RDK::GetEngineLock();
QString class_name = InputClassName->text();
if(!engine)
return;
//
if(class_name.isEmpty())
return;
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()->GetComponent(ComponentName->text().toUtf8().data(), true);
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!container)
{
MessageComp->setText("Component with this name doesn't exist in the model");
if(!storage)
return;
}
// - ->
// ->
if(!storage->CheckClass(class_name.toUtf8().data()))
{
accept();
MessageClass->setText("Enter Class Name");
AddButton->setEnabled(true);
}
else
else // -
{
QString oldMessage = MessageClass->text();
std::string lib_name = storage->FindCollection(class_name.toUtf8().data())->GetName();
MessageClass->setText("Class \"" + class_name +"\" already exists in \"" + QString::fromStdString(lib_name) + "\" library"
+"\n" + "If you want to replace it, press \"Ok\" again");
// Message -> "" ->
if(oldMessage == MessageClass->text())
{
Replace = true;
accept();
}
MessageClass->setText("Class \"" + class_name +"\" already exists in \"" + QString::fromStdString(lib_name) + "\" library");
ReplaceButton->setEnabled(true);
Replace = true;
}
}
const bool CrClassDialog::GetReplace() const
......@@ -556,8 +589,30 @@ const std::string CrClassDialog::GetClassName() const
return InputClassName->text().toUtf8().data();
}
const std::string CrClassDialog::GetCompName() const
const std::string CrClassDialog::GetLibName() const
{
return ComponentName->text().toUtf8().data();
return Libraries->currentText().toUtf8().data();
}
// /
DeleteDialog::DeleteDialog(QString title, QString message, QWidget* pwgt)
{
setWindowTitle(title);
QLabel* info_message = new QLabel(message);
QPushButton* ok_button = new QPushButton("Ok");
QPushButton* cancel_button = new QPushButton("Cancel");
connect(ok_button, SIGNAL(clicked()), this, SLOT(accept()));
connect(cancel_button, SIGNAL(clicked()), this, SLOT(reject()));
QHBoxLayout* hbox_layout = new QHBoxLayout;
hbox_layout->addWidget(ok_button);
hbox_layout->addWidget(cancel_button);
QVBoxLayout* vbox_layout = new QVBoxLayout;
vbox_layout->addWidget(info_message);
vbox_layout->addLayout(hbox_layout);
setLayout(vbox_layout);
}
......@@ -9,6 +9,7 @@
#include <QModelIndex>
#include <QListWidget>
#include <QDialog>
#include <QComboBox>
namespace Ui {
class UClassesListWidget;
......@@ -77,6 +78,7 @@ class CrLibDialog: public QDialog
private:
QLineEdit* InputLibName;
QLabel* Message;
QPushButton* AddButton;
public:
CrLibDialog(QWidget* pwgt = 0);
......@@ -92,22 +94,28 @@ class CrClassDialog: public QDialog
{
Q_OBJECT
private:
QLineEdit* InputClassName;
QLineEdit* ComponentName;
QLabel* Info;
QLabel* MessageLib;
QComboBox* Libraries;
QLabel* MessageClass;
QLabel* MessageComp;
// replace
QLineEdit* InputClassName;
QPushButton* AddButton;
QPushButton* ReplaceButton;
bool Replace;
public:
CrClassDialog(QString lib_name, QWidget* pwgt = 0);
const bool GetReplace() const;
CrClassDialog(QStringList libs, QString cur_lib, QWidget* pwgt = 0);
const std::string GetClassName() const;
const std::string GetCompName() const;
const std::string GetLibName() const;
const bool GetReplace() const;
public slots:
void ProcessInput();
};
class DeleteDialog: public QDialog
{
Q_OBJECT
public:
DeleteDialog(QString title, QString message, QWidget* pwgt = 0);
};
#endif // UCLASSESLISTWIDGET_H
......@@ -708,3 +708,13 @@ void UDrawEngineImageWidget::SetApplication(RDK::UApplication *app)
{
Application=app;
}
///
std::string UDrawEngineImageWidget::GetSelectedCmponent()
{
if(ComponentName.isEmpty())
std::string one = ComponentName.toUtf8().data();
if(selectedComponent.empty())
std::string two = selectedComponent;
return selectedComponent;
}
......@@ -55,6 +55,9 @@ public:
///
void SetApplication(RDK::UApplication *app);
///
std::string GetSelectedCmponent();
public slots:
//
void componentViewOrBreakLink();
......
......@@ -108,3 +108,10 @@ void UDrawEngineWidget::updateScheme(bool reloadXml)
{
modelScheme->reDrawScheme(reloadXml);
}
std::string UDrawEngineWidget::GetSelectedCmponent()
{
if(!modelScheme)
return "";
return modelScheme->GetSelectedCmponent();
}
......@@ -35,6 +35,9 @@ public:
//
void resizeEvent(QResizeEvent*);
/// UDrawEngineImageWidget
std::string GetSelectedCmponent();
public slots:
void componentDoubleClick(QString name);
void componentSingleClick(QString name);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment