Commit 19ed8385 authored by vlad_burin's avatar vlad_burin
Browse files

RTLib class updated.

GUI updated (search bar is now common for three tabs)

--HG--
branch : RunTimeLibsTest
parent 43db99c44d31
......@@ -404,11 +404,6 @@ URuntimeLibrary::~URuntimeLibrary(void)
// --------------------------
vector<string>& URuntimeLibrary::GetClassesStructures()
{
return ClassesStructures;
}
///
const std::string& URuntimeLibrary::GetLibPath() const
{
......@@ -465,13 +460,20 @@ bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, UContainer
CurrentComponentStruct.SaveToFile(LibPath+"/"+new_class_name+".xml");
try
{
UEPtr<UContainer> cont_1 = CreateClassSample(Storage, CurrentComponentStruct);
if(UploadClass(new_class_name, cont_1))
ClassesStructures.push_back(buff);
}
catch(UException &ex)
{
Storage->GetLogger()->LogMessage(RDK_EX_ERROR, __FUNCTION__, ex.what());
}
return true;
}
......@@ -490,30 +492,24 @@ bool URuntimeLibrary::ReplaceClass(const std::string &new_class_name, UContainer
/// Storage
bool URuntimeLibrary::DelClass(const std::string &class_name)
{
// TODO
URuntimeLibrary *library = nullptr;
// .
if(Storage->CheckClass(class_name))
{
UEPtr<ULibrary> lib = Storage->GetCollection(class_name);
library = dynamic_cast<URuntimeLibrary*>(lib.Get());
//
if(Storage->FindCollection(class_name).Get()!= dynamic_cast<ULibrary*>(this))
return false;
Storage->DelClass(Storage->FindClassId(class_name));
}
auto ClStr = library->GetClassesStructures();
for(auto it = ClStr.begin(); it != ClStr.end(); ++it)
for(auto it = ClassesStructures.begin(); it != ClassesStructures.end(); ++it)
{
// xml
CurrentComponentStruct.Load(*it,"");
std::string search_name = CurrentComponentStruct.GetNodeAttribute("RTname");
if(class_name == search_name)
{
ClStr.erase(it);
std::string xml_path = "../../../RTlibs/" + library->GetName() +"/" + search_name + ".xml";
ClassesStructures.erase(it);
std::string xml_path = LibPath +"/" + search_name + ".xml";
RDK::DeleteFile(xml_path.c_str());
break;
}
......@@ -522,7 +518,7 @@ bool URuntimeLibrary::DelClass(const std::string &class_name)
bool URuntimeLibrary::DeleteOwnDirectory(void)
{
RDK::DeleteDirectory(LibPath.c_str());
return (!RDK::DeleteDirectory(LibPath.c_str()));
}
// --------------------------
......@@ -544,7 +540,6 @@ UEPtr<UContainer> URuntimeLibrary::CreateClassSample(UStorage *storage, USerStor
if(!cont->LoadComponent(&xml,true))
{
//log
storage->ReturnObject(cont);
return 0;
}
......@@ -566,13 +561,16 @@ void URuntimeLibrary::CreateClassSamples(UStorage *storage)
UEPtr<UContainer> cont=CreateClassSample(storage, CurrentComponentStruct);
if(!cont)
return;
std::string class_name=CurrentComponentStruct.GetNodeAttribute("RTname");
UploadClass(class_name,cont);
}
catch(UException &)
catch(UException &ex)
{
// smth
Storage->GetLogger()->LogMessage(RDK_EX_ERROR, __FUNCTION__, ex.what());
}
}
}
......
......@@ -213,7 +213,6 @@ virtual ~URuntimeLibrary(void);
// --------------------------
//
// --------------------------
vector<string>& GetClassesStructures();
///
const std::string& GetLibPath() const;
......
......@@ -885,16 +885,29 @@ const string& UStorage::GetCollectionVersion(int index)
return CollectionList[index]->GetVersion();
}
// runtime-,
// 'buffer'
void UStorage::GetRTlibsNameList(std::string &buffer) const
{
for(size_t i=0;i<CollectionList.size();i++)
{
UEPtr<ULibrary> lib = CollectionList[i];
if(lib && lib->GetType() == 2)
{
buffer.append(lib->GetName());
buffer.append(",");
}
}
buffer.erase(buffer.length()-1);
}
///
bool UStorage::AddClassToCollection(const std::string &new_class_name, bool force_replace, UContainer *newclass, const std::string &lib_name)
{
try
{
//
// + Upload
//
URuntimeLibrary *library = nullptr;
for(size_t i=0;i<CollectionList.size();i++)
......@@ -907,13 +920,19 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, bool forc
}
//
// TODO ,
if(CheckClass(new_class_name))
{
//
if(force_replace)
{
library->ReplaceClass(new_class_name, newclass);
//
URuntimeLibrary *lib = dynamic_cast<URuntimeLibrary*>(FindCollection(new_class_name).Get());
//
lib->DelClass(new_class_name);
//
library->AddNewClass(new_class_name, newclass);
}
else
{
......@@ -938,8 +957,6 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, bool forc
/// RT
bool UStorage::DelClassFromCollection(const std::string &class_name, const std::string &lib_name)
{
//
// + Upload
URuntimeLibrary *library = nullptr;
for(size_t i=0;i<CollectionList.size();i++)
......@@ -950,20 +967,17 @@ bool UStorage::DelClassFromCollection(const std::string &class_name, const std::
library = dynamic_cast<URuntimeLibrary*>(lib.Get());
}
}
// TODO Storage
//
//
library->DelClass(class_name);
return true;
}
///
bool UStorage::CreateRuntimeCollection(const std::string &lib_name)
{
if(lib_name.empty())
return false;
// TODO
if(GetCollection(lib_name) != nullptr)
return false;
......
......@@ -297,6 +297,10 @@ const string& GetCollectionName(int index);
//
const string& GetCollectionVersion(int index);
// runtime-,
// 'buffer'
void GetRTlibsNameList(std::string &buffer) const;
//
//virtual bool AddClass(UContainer *newclass);
......
......@@ -5,7 +5,7 @@
#include <QDragMoveEvent>
#include <QDrag>
#include <QDebug>
#include <QDialog>
#include <QPushButton>
UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app) :
UVisualControllerWidget(parent, app),
......@@ -53,17 +53,9 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
// runtime-
auto storage = RDK::GetStorageLock();
int lib_num = storage->GetNumCollections();
componentNames.clear();
for (int i = 0; i <lib_num;i++)
{
storage->GetCollection(i);
RDK::UEPtr<RDK::ULibrary> lib = storage->GetCollection(i);
if(lib && lib->GetType() == 2)
{
componentNames.append(QString::fromStdString(lib->GetName()));
}
}
std::string buff;
storage->GetRTlibsNameList(buff);
componentNames = QString(buff.c_str()).split(",");
ui->listWidgetRTlibs->addItems(componentNames);
ui->listWidgetRTlibs->sortItems(Qt::AscendingOrder);
......@@ -103,6 +95,10 @@ UClassesListWidget::~UClassesListWidget()
QString UClassesListWidget::selctedClass() const
{
// sigfault
if(ui->listWidgetStorageByName->selectedItems().size() ==0)
return QString();
switch(ui->tabWidget->currentIndex())
{
case 0:
......@@ -150,7 +146,52 @@ void UClassesListWidget::dragEvent(QModelIndex index)
drag->exec(Qt::CopyAction, Qt::CopyAction);
}
void UClassesListWidget::on_lineEdit_textChanged(const QString &arg1)
//
void UClassesListWidget::on_listWidgetRTlibs_itemSelectionChanged()
{
QListWidgetItem* item = ui->listWidgetRTlibs->currentItem();
QString lib_name = item->text();
//
const char* stringBuff = Storage_GetLibraryClassNames(lib_name.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
QString className;
ui->listWidgetRTlibClasses->clear();
foreach(className, libClasses)
{
if(className != "")
{
ui->listWidgetRTlibClasses->addItem(className);
}
}
}
void UClassesListWidget::tab0_textChanged(const QString &arg1)
{
ui->listWidgetStorageByName->clear();
//
const char * stringBuff = Storage_GetClassesNameList();
QStringList componentNames = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
QString str;
foreach(str, componentNames)
{
if(str != "")
{
if (str.contains(arg1, Qt::CaseInsensitive))
{
ui->listWidgetStorageByName->addItem(str);
}
}
}
ui->listWidgetStorageByName->sortItems(Qt::AscendingOrder);
}
void UClassesListWidget::tab1_textChanged(const QString &arg1)
{
ui->treeWidgetStorageByLibs->clear();
......@@ -211,50 +252,88 @@ void UClassesListWidget::on_lineEdit_textChanged(const QString &arg1)
}
}
ui->treeWidgetStorageByLibs->sortItems(0, Qt::AscendingOrder);
//
/*QMessageBox::StandardButton reply = QMessageBox::question(this, "Warning", "Component with this name is exists. Continue by adding the next number?", QMessageBox::Yes|QMessageBox::Cancel);
if (reply == QMessageBox::Cancel) return;*/
}
void UClassesListWidget::on_listWidgetRTlibs_itemSelectionChanged()
void UClassesListWidget::tab2_textChanged(const QString &arg1)
{
QListWidgetItem* item = ui->listWidgetRTlibs->currentItem();
QString lib_name = item->text();
ui->listWidgetRTlibs->clear();
//
const char* stringBuff = Storage_GetLibraryClassNames(lib_name.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
// runtime-
// TODO Storage
auto storage = RDK::GetStorageLock();
std::string buff;
storage->GetRTlibsNameList(buff);
QStringList componentNames = QString(buff.c_str()).split(",");
QString className;
ui->listWidgetRTlibClasses->clear();
foreach(className, libClasses)
QString str;
foreach(str, componentNames)
{
if(className != "")
if(str != "")
{
ui->listWidgetRTlibClasses->addItem(className);
if (str.contains(arg1, Qt::CaseInsensitive))
{
ui->listWidgetRTlibs->addItem(str);
}
}
}
ui->listWidgetRTlibs->sortItems(Qt::AscendingOrder);
}
void UClassesListWidget::on_lineEditSearch_textChanged(const QString &arg1)
{
switch(ui->tabWidget->currentIndex())
{
case 0:
{
tab0_textChanged(arg1);
break;
}
case 1:
{
tab1_textChanged(arg1);
break;
}
case 2:
{
tab2_textChanged(arg1);
break;
}
}
}
// Actions
void UClassesListWidget::CreateRTlibrary()
{
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
CrLibDialog* dialog = new CrLibDialog;
if(dialog->exec() == QDialog::Accepted)
{
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
if(!storage)
return;
std::string lib_name = ui->lineEdit->text().toUtf8().data();
std::string lib_name = dialog->GetLibName();
storage->CreateRuntimeCollection(lib_name);
storage->CreateRuntimeCollection(lib_name);
AUpdateInterface();
AUpdateInterface();
}
delete dialog;
}
void UClassesListWidget::DeleteRTlibrary()
{
//
if(ui->listWidgetRTlibs->selectedItems().size() == 0)
{
return;
}
QListWidgetItem* item = ui->listWidgetRTlibs->currentItem();
QString lib_name = item->text().toUtf8().data();
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
......@@ -269,25 +348,53 @@ void UClassesListWidget::DeleteRTlibrary()
void UClassesListWidget::AddNewClass()
{
//
if(ui->listWidgetRTlibs->selectedItems().size() == 0)
{
return;
}
RDK::UELockPtr<RDK::UEngine> engine=RDK::GetEngineLock();
if(!engine)
return;
return;
std::string cont_name = ui->lineEdit->text().toUtf8().data();
std::string new_comp_name = ui->lineEditSearch->text().toUtf8().data();
std::string lib_name = ui->listWidgetRTlibs->currentItem()->text().toUtf8().data();
// ->
if(!engine->GetModel())
{
return;
}
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()->GetComponent(cont_name, true);
QString lib_name = ui->listWidgetRTlibs->currentItem()->text();
engine->GetEnvironment()->
GetStorage()->AddClassToCollection(new_comp_name,true,container,lib_name);
CrClassDialog* dialog = new CrClassDialog(lib_name);
if(dialog->exec() == QDialog::Accepted)
{
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()->GetComponent(dialog->GetCompName(), true);
//
if(!container)
{
delete dialog;
return;
}
engine->GetEnvironment()->
GetStorage()->AddClassToCollection(dialog->GetClassName(),dialog->GetReplace(),
container,lib_name.toUtf8().data());
AUpdateInterface();
AUpdateInterface();
}
delete dialog;
}
void UClassesListWidget::DeleteClass()
{
//
if(ui->listWidgetRTlibs->selectedItems().empty() || ui->listWidgetRTlibClasses->selectedItems().empty())
{
return;
}
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
......@@ -298,8 +405,159 @@ void UClassesListWidget::DeleteClass()
item = ui->listWidgetRTlibClasses->currentItem();
QString class_name = item->text();
//TODO +
//
storage->DelClassFromCollection(class_name.toUtf8().data(), lib_name.toUtf8().data());
AUpdateInterface();
}
//
CrLibDialog::CrLibDialog(QWidget* pwgt)
{
setWindowTitle("Create New Library");
InputLibName = new QLineEdit;
Message = new QLabel("Enter library name");
QPushButton* ok_button = new QPushButton("Ok");
QPushButton* cancel_button = new QPushButton("Cancel");
connect(ok_button,SIGNAL(clicked()),this,SLOT(ProcessInput()));
connect(cancel_button,SIGNAL(clicked()),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(Message);
vbox_layout->addWidget(InputLibName);
vbox_layout->addLayout(hbox_layout);
setLayout(vbox_layout);
}
void CrLibDialog::ProcessInput()
{
//
if(InputLibName->text().isEmpty())
{
return;
}
std::string lib_name = InputLibName->text().toUtf8().data();
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
//
if(!storage->GetCollection(lib_name))
accept(); // -
else
Message->setText("Library with this name already exists");
}
const std::string CrLibDialog::GetLibName() const
{
return InputLibName->text().toUtf8().data();
}
//
CrClassDialog::CrClassDialog(QString lib_name, QWidget* pwgt) :Replace(false)
{
setWindowTitle("Add New Class");
Info = new QLabel("Adding Class to \"" + lib_name + "\" library");
MessageClass = new QLabel("Enter Class name");
InputClassName = new QLineEdit;
MessageComp = new QLabel("Enter Comp name");
ComponentName = new QLineEdit;
QPushButton* ok_button = new QPushButton("Ok");
QPushButton* cancel_button = new QPushButton("Cancel");
connect(ok_button,SIGNAL(clicked()),this,SLOT(ProcessInput()));
connect(cancel_button,SIGNAL(clicked()),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);
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())
{
return;
}
RDK::UELockPtr<RDK::UStorage> storage=RDK::GetStorageLock();
if(!storage)
return;
//
RDK::UELockPtr<RDK::UEngine> engine=RDK::GetEngineLock();
if(!engine)
return;
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()->GetComponent(ComponentName->text().toUtf8().data(), true);
if(!container)
{
MessageComp->setText("Component with this name doesn't exist in the model");
return;
}
// - ->
if(!storage->CheckClass(class_name.toUtf8().data()))
{
accept();
}
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())
{