Commit fdf7e926 authored by vladburin's avatar vladburin
Browse files

GUI Qt UClassesListWidget updated

+Get info about which component is selected in the model
+Setting the name of the component
+Highlighting the RT libraries and their components

--HG--
branch : RunTimeLibsTest
parent ec89fb953e41
......@@ -1613,7 +1613,7 @@ int UEngine::Storage_CreateClass(const char* stringid, const char *class_name, c
if(!library)
return RDK_E_STORAGE_COLLECTION_NOT_FOUND;
if(!Storage->AddClassToCollection(class_name, false, sample,collection_name))
if(!Storage->AddClassToCollection(class_name, "", false, sample,collection_name))
return RDK_E_STORAGE_ADD_COLLECTION_FAIL;
AccessCache.clear();
......
......@@ -436,7 +436,7 @@ bool URuntimeLibrary::LoadCompDescriptions()
}
/// ( )
bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, UContainer *newclass)
bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, const std::string &new_comp_name, UContainer *newclass)
{
UEPtr<UContainer> p = newclass;
UEPtr<UNet> cont = dynamic_pointer_cast<UNet>(p);
......@@ -452,6 +452,7 @@ bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, UContainer
// XML RTname
cont->SaveComponent(&CurrentComponentStruct, true, ptPubParameter);
CurrentComponentStruct.SelectNode(cont->GetName());
CurrentComponentStruct.RenameNode(new_comp_name);
CurrentComponentStruct.SetNodeAttribute("RTname", new_class_name);
CurrentComponentStruct.Save(buff);
......@@ -464,7 +465,7 @@ bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, UContainer
{
UEPtr<UContainer> cont_1 = CreateClassSample(Storage, CurrentComponentStruct);
//
if(UploadClass(new_class_name, cont_1))
ClassesStructures.push_back(buff);
......@@ -477,18 +478,6 @@ bool URuntimeLibrary::AddNewClass(const std::string &new_class_name, UContainer
return true;
}
///
bool URuntimeLibrary::ReplaceClass(const std::string &new_class_name, UContainer *newclass)
{
// .
DelClass(new_class_name);
//
AddNewClass(new_class_name,newclass);
return true;
}
/// Storage
bool URuntimeLibrary::DelClass(const std::string &class_name)
{
......
......@@ -218,10 +218,7 @@ virtual ~URuntimeLibrary(void);
const std::string& GetLibPath() const;
/// (, )
bool AddNewClass(const std::string &new_class_name, UContainer *newclass);
/// (, )
bool ReplaceClass(const std::string &new_class_name, UContainer *newclass);
bool AddNewClass(const std::string &new_class_name, const std::string &new_comp_name, UContainer *newclass);
/// Storage
bool DelClass(const std::string &class_name);
......
......@@ -902,7 +902,7 @@ void UStorage::GetRTlibsNameList(std::string &buffer) const
}
///
bool UStorage::AddClassToCollection(const std::string &new_class_name, bool force_replace, UContainer *newclass, const std::string &lib_name)
bool UStorage::AddClassToCollection(const std::string &new_class_name, const std::string &new_comp_name, bool force_replace, UContainer *newclass, const std::string &lib_name)
{
try
{
......@@ -931,7 +931,7 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, bool forc
//
lib->DelClass(new_class_name);
//
library->AddNewClass(new_class_name, newclass);
library->AddNewClass(new_class_name, new_comp_name, newclass);
}
else
......@@ -941,7 +941,7 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, bool forc
}
else
{
library->AddNewClass(new_class_name, newclass);
library->AddNewClass(new_class_name, new_comp_name, newclass);
}
}
......
......@@ -314,7 +314,7 @@ virtual bool LoadRuntimeCollection(const std::string &lib_name);
/// ( )
/// force_replace = true
virtual bool AddClassToCollection(const std::string &new_class_name, bool force_replace, UContainer *newclass, const std::string &lib_name);
virtual bool AddClassToCollection(const std::string &new_class_name, const std::string &new_comp_name, bool force_replace, UContainer *newclass, const std::string &lib_name);
/// RT
virtual bool DelClassFromCollection(const std::string &class_name, const std::string &lib_name);
......
#include "UClassesListWidget.h"
#include "ui_UClassesListWidget.h"
#include "UDrawEngineWidget.h"
#include <QMimeData>
#include <QDragMoveEvent>
#include <QDrag>
......@@ -8,7 +7,7 @@
#include <QPushButton>
UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app) :
UVisualControllerWidget(parent, app),
UVisualControllerWidget(parent, app), ModelScheme(nullptr),
ui(new Ui::UClassesListWidget)
{
ui->setupUi(this);
......@@ -16,25 +15,62 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
UpdateInterval = 0; //
setAccessibleName("UClassesListWidget"); //
//
// RT
auto storage = RDK::GetStorageLock();
std::string buff;
storage->GetRTlibsNameList(buff);
QStringList RTlibsNames = QString(buff.c_str()).split(",");
// RT
QStringList RTclassesNames;
QString str;
foreach(str, RTlibsNames)
{
const char * stringBuff;
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
//
if((stringBuff[0] == '\0'))
{
Engine_FreeBufString(stringBuff);
continue;
}
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
RTclassesNames += libClasses;
}
//
const char * stringBuff = Storage_GetClassesNameList();
QStringList componentNames = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
ui->listWidgetStorageByName->addItems(componentNames);
foreach(str, componentNames)
{
QListWidgetItem* item = new QListWidgetItem(ui->listWidgetStorageByName);
if(RTclassesNames.indexOf(str)!=-1)
item->setBackgroundColor(Qt::lightGray);
item->setText(str);
ui->listWidgetStorageByName->addItem(item);
}
ui->listWidgetStorageByName->sortItems(Qt::AscendingOrder);
//
//
stringBuff = Storage_GetClassLibrariesList();
componentNames = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
QString str;
bool isRTlib = false;
foreach(str, componentNames)
{
if(str != "")
{
isRTlib = false;
// RT
if(RTlibsNames.indexOf(str)!=-1)
isRTlib = true;
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidgetStorageByLibs);
item->setExpanded(true);
item->setText(0, str);
if(isRTlib)
item->setBackgroundColor(0,Qt::darkGray);
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
......@@ -45,6 +81,8 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
{
QTreeWidgetItem* classItem = new QTreeWidgetItem(item);
classItem->setText(0, className);
if(isRTlib)
classItem->setBackgroundColor(0,Qt::lightGray);
}
}
}
......@@ -52,17 +90,14 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
ui->treeWidgetStorageByLibs->sortItems(0, Qt::AscendingOrder);
// runtime-
auto storage = RDK::GetStorageLock();
std::string buff;
storage->GetRTlibsNameList(buff);
componentNames = QString(buff.c_str()).split(",");
ui->listWidgetRTlibs->addItems(componentNames);
ui->listWidgetRTlibs->addItems(RTlibsNames);
ui->listWidgetRTlibs->sortItems(Qt::AscendingOrder);
//
connect(ui->treeWidgetStorageByLibs, SIGNAL(pressed(QModelIndex)), this, SLOT(dragEvent(QModelIndex)));
connect(ui->listWidgetStorageByName, SIGNAL(pressed(QModelIndex)), this, SLOT(dragEvent(QModelIndex)));
connect(ui->listWidgetRTlibClasses, SIGNAL(pressed(QModelIndex)), this, SLOT(dragEvent(QModelIndex)));
//
connect(ui->treeWidgetStorageByLibs, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SIGNAL(classSelectionChanged()));
......@@ -132,6 +167,11 @@ void UClassesListWidget::AUpdateInterface(void)
ui->listWidgetRTlibs->sortItems(Qt::AscendingOrder);
}
void UClassesListWidget::SetModelScheme(UDrawEngineImageWidget* model)
{
ModelScheme = model;
}
void UClassesListWidget::dragEvent(QModelIndex index)
{
QByteArray itemData;
......@@ -173,11 +213,35 @@ void UClassesListWidget::tab0_textChanged(const QString &arg1)
{
ui->listWidgetStorageByName->clear();
// RT
auto storage = RDK::GetStorageLock();
std::string buff;
storage->GetRTlibsNameList(buff);
QStringList RTlibsNames = QString(buff.c_str()).split(",");
// RT
QStringList RTclassesNames;
QString str;
foreach(str, RTlibsNames)
{
const char * stringBuff;
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
//
if((stringBuff[0] == '\0'))
{
Engine_FreeBufString(stringBuff);
continue;
}
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
RTclassesNames += libClasses;
}
//
const char * stringBuff = Storage_GetClassesNameList();
QStringList componentNames = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
QString str;
foreach(str, componentNames)
{
......@@ -185,7 +249,11 @@ void UClassesListWidget::tab0_textChanged(const QString &arg1)
{
if (str.contains(arg1, Qt::CaseInsensitive))
{
ui->listWidgetStorageByName->addItem(str);
QListWidgetItem* item = new QListWidgetItem(ui->listWidgetStorageByName);
if(RTclassesNames.indexOf(str)!=-1)
item->setBackgroundColor(Qt::lightGray);
item->setText(str);
ui->listWidgetStorageByName->addItem(item);
}
}
}
......@@ -196,20 +264,52 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
{
ui->treeWidgetStorageByLibs->clear();
// RT
auto storage = RDK::GetStorageLock();
std::string buff;
storage->GetRTlibsNameList(buff);
QStringList RTlibsNames = QString(buff.c_str()).split(",");
// RT
QStringList RTclassesNames;
QString str;
foreach(str, RTlibsNames)
{
const char * stringBuff;
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
//
if((stringBuff[0] == '\0'))
{
Engine_FreeBufString(stringBuff);
continue;
}
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
RTclassesNames += libClasses;
}
//
const char * stringBuff = Storage_GetClassLibrariesList();
QStringList componentNames = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
QString str;
bool isRTlib = false;
foreach(str, componentNames)
{
if(str != "")
{
isRTlib = false;
// RT
if(RTlibsNames.indexOf(str)!=-1)
isRTlib = true;
if (str.contains(arg1, Qt::CaseInsensitive))
{
QTreeWidgetItem* item = new QTreeWidgetItem(ui->treeWidgetStorageByLibs);
item->setExpanded(true);
item->setText(0, str);
if(isRTlib)
item->setBackgroundColor(0,Qt::darkGray);
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
......@@ -220,6 +320,8 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
{
QTreeWidgetItem* classItem = new QTreeWidgetItem(item);
classItem->setText(0, className);
if(isRTlib)
classItem->setBackgroundColor(0,Qt::lightGray);
}
}
......@@ -230,6 +332,8 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
bool isLibFind = false;
item->setExpanded(true);
item->setText(0, str);
if(isRTlib)
item->setBackgroundColor(0,Qt::darkGray);
stringBuff = Storage_GetLibraryClassNames(str.toLocal8Bit());
QStringList libClasses = QString(stringBuff).split(",");
Engine_FreeBufString(stringBuff);
......@@ -241,6 +345,8 @@ void UClassesListWidget::tab1_textChanged(const QString &arg1)
isLibFind = true;
QTreeWidgetItem* classItem = new QTreeWidgetItem(item);
classItem->setText(0, className);
if(isRTlib)
classItem->setBackgroundColor(0,Qt::lightGray);
}
}
if (!isLibFind)
......@@ -361,10 +467,17 @@ void UClassesListWidget::AddNewClass()
{
RDK::UELockPtr<RDK::UEngine> engine=RDK::GetEngineLock();
//
//
if(!engine || !engine->GetModel())
return;
//
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()
->GetComponent(ModelScheme->GetSelectedCmponent(), true);
//
if(!container)
return;
// ( )
QString lib_name = "";
if(ui->listWidgetRTlibs->currentItem())
......@@ -374,21 +487,12 @@ void UClassesListWidget::AddNewClass()
engine->GetModel()->GetStorage()->GetRTlibsNameList(buff);
QStringList libs_names = QString(buff.c_str()).split(",");
CrClassDialog* dialog = new CrClassDialog(libs_names,lib_name);
CrClassDialog* dialog = new CrClassDialog(libs_names, lib_name, QString::fromStdString(container->GetName()));
if(dialog->exec() == QDialog::Accepted)
{
//
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()
->GetComponent(static_cast<UDrawEngineWidget*>(this->parentWidget()->parentWidget()->parentWidget())->GetSelectedCmponent(), true);
//
if(!container)
{
delete dialog;
return;
}
engine->GetEnvironment()->
GetStorage()->AddClassToCollection(dialog->GetClassName(),dialog->GetReplace(),
container,lib_name.toUtf8().data());
GetStorage()->AddClassToCollection(dialog->GetClassName(), dialog->GetCompName(),
dialog->GetReplace(), container, dialog->GetLibName());
AUpdateInterface();
}
......@@ -494,7 +598,7 @@ const std::string CrLibDialog::GetLibName() const
}
//
CrClassDialog::CrClassDialog(QStringList libs, QString cur_lib, QWidget* pwgt)
CrClassDialog::CrClassDialog(QStringList libs, QString cur_lib, QString cur_comp_name, QWidget* pwgt)
{
setWindowTitle("Add New Class");
......@@ -508,6 +612,10 @@ CrClassDialog::CrClassDialog(QStringList libs, QString cur_lib, QWidget* pwgt)
Libraries->setCurrentIndex(index);
}
MessageComp = new QLabel("Enter New Component Name");
InputCompName = new QLineEdit(cur_comp_name);
MessageClass = new QLabel("Enter Class Name");
InputClassName = new QLineEdit;
......@@ -531,6 +639,8 @@ CrClassDialog::CrClassDialog(QStringList libs, QString cur_lib, QWidget* pwgt)
QVBoxLayout* vbox_layout = new QVBoxLayout;
vbox_layout->addWidget(MessageLib);
vbox_layout->addWidget(Libraries);
vbox_layout->addWidget(MessageComp);
vbox_layout->addWidget(InputCompName);
vbox_layout->addWidget(MessageClass);
vbox_layout->addWidget(InputClassName);
vbox_layout->addLayout(hbox_layout);
......@@ -540,7 +650,7 @@ CrClassDialog::CrClassDialog(QStringList libs, QString cur_lib, QWidget* pwgt)
void CrClassDialog::ProcessInput()
{
//
if(InputClassName->text().isEmpty())
if(InputClassName->text().isEmpty() || InputCompName->text().isEmpty())
{
MessageClass->setText("Enter Class Name");
AddButton->setEnabled(false);
......@@ -570,7 +680,7 @@ void CrClassDialog::ProcessInput()
MessageClass->setText("Enter Class Name");
AddButton->setEnabled(true);
}
else // -
else// -
{
std::string lib_name = storage->FindCollection(class_name.toUtf8().data())->GetName();
MessageClass->setText("Class \"" + class_name +"\" already exists in \"" + QString::fromStdString(lib_name) + "\" library");
......@@ -589,6 +699,11 @@ const std::string CrClassDialog::GetClassName() const
return InputClassName->text().toUtf8().data();
}
const std::string CrClassDialog::GetCompName() const
{
return InputCompName->text().toUtf8().data();
}
const std::string CrClassDialog::GetLibName() const
{
return Libraries->currentText().toUtf8().data();
......
......@@ -35,6 +35,8 @@ public:
virtual void AUpdateInterface(void);
void SetModelScheme(UDrawEngineImageWidget* model);
public slots:
void dragEvent(QModelIndex index);
......@@ -66,7 +68,7 @@ public slots:
void DeleteClass();
private:
UDrawEngineImageWidget* ModelScheme;
Ui::UClassesListWidget *ui;
};
......@@ -97,14 +99,17 @@ private:
QLabel* MessageLib;
QComboBox* Libraries;
QLabel* MessageComp;
QLineEdit* InputCompName;
QLabel* MessageClass;
QLineEdit* InputClassName;
QPushButton* AddButton;
QPushButton* ReplaceButton;
bool Replace;
public:
CrClassDialog(QStringList libs, QString cur_lib, QWidget* pwgt = 0);
CrClassDialog(QStringList libs, QString cur_lib, QString cur_comp_name, QWidget* pwgt = 0);
const std::string GetClassName() const;
const std::string GetCompName() const;
const std::string GetLibName() const;
const bool GetReplace() const;
public slots:
......
......@@ -712,9 +712,8 @@ void UDrawEngineImageWidget::SetApplication(RDK::UApplication *app)
///
std::string UDrawEngineImageWidget::GetSelectedCmponent()
{
if(ComponentName.isEmpty())
std::string one = ComponentName.toUtf8().data();
if(selectedComponent.empty())
std::string two = selectedComponent;
return selectedComponent;
if(!selectedComponent.empty())
return selectedComponent;
else
return std::string();
}
......@@ -23,6 +23,7 @@ UDrawEngineWidget::UDrawEngineWidget(QWidget *parent, RDK::UApplication *app) :
modelScheme = new UDrawEngineImageWidget(ui->scrollArea);
classesList->SetModelScheme(modelScheme);
modelScheme->SetApplication(app);
connect(modelScheme, SIGNAL(componentSelected(QString)), this, SIGNAL(componentSelectedFromScheme(QString)));
connect(modelScheme, SIGNAL(componentDoubleClick(QString)), this, SIGNAL(componentDoubleClickFromScheme(QString)));
......@@ -108,10 +109,3 @@ void UDrawEngineWidget::updateScheme(bool reloadXml)
{
modelScheme->reDrawScheme(reloadXml);
}
std::string UDrawEngineWidget::GetSelectedCmponent()
{
if(!modelScheme)
return "";
return modelScheme->GetSelectedCmponent();
}
......@@ -35,9 +35,6 @@ 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