Commit 9327724c authored by vlad_burin's avatar vlad_burin
Browse files

GUI Qt UClassesListWidget updated: added error occured warnings and drop from...

GUI Qt UClassesListWidget updated: added error occured warnings and drop from UDrawEngineImageWidget
FreeObjectsStorageByClass() funciton created to delete free objects of specific class
In Storage->DelClass() added call of FreeObjectsStorageByClass() to work more properly

--HG--
branch : RunTimeLibsTest
parent ef010c384f3c
......@@ -236,6 +236,10 @@ void UStorage::DelClass(const UId &classid, bool force)
if(!force)
{
FreeObjectsStorageByClass(classid);
//
if(temp != ObjectsStorage.end() && temp->second.empty())
ObjectsStorage.erase(temp);
if(temp != ObjectsStorage.end() && temp->second.size() > 0)
throw EObjectStorageNotEmpty(classid);
}
......@@ -576,7 +580,7 @@ size_t UStorage::CalcNumObjects(const string &classname) const
}
//
//
void UStorage::FreeObjectsStorage(bool force)
{
for(UObjectsStorageIterator instances=ObjectsStorage.begin(),iend=ObjectsStorage.end();
......@@ -656,6 +660,79 @@ void UStorage::FreeObjectsStorage(bool force)
}
}
//
void UStorage::FreeObjectsStorageByClass(const UId &classid)
{
UObjectsStorageIterator instances=ObjectsStorage.find(classid);
if(instances==ObjectsStorage.end())
return;
std::string object_class_name=FindClassName(instances->first);
if(instances->second.empty())
return;
size_t size=instances->second.size();
size_t count=0;
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects of class ")+object_class_name+" has begun");
for(list<UInstancesStorageElement>::iterator I=instances->second.begin(); I != instances->second.end();)
{
std::string object_name=I->Object->GetName();
if(I->UseFlag)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, std::string("Can't destroy objects by name ")+object_name+": object in use!");
}
if(!I->UseFlag)
{
list<UInstancesStorageElement>::iterator K;
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects by name ")+object_name);
K=I; ++K;
UEPtr<UContainer> object=I->Object;
PopObject(instances,I);
RDK_SYS_TRY
{
try
{
UVirtualMethodFactory* virtual_factory=FindVirualMethodFactory(object);
if(virtual_factory)
{
virtual_factory->FreeComponent();
}
delete object;
++count;
}
catch(...)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_FATAL, __FUNCTION__, std::string("Exception raised when object ")+object_name);
}
}
RDK_SYS_CATCH
{
if(Logger)
Logger->ProcessException(RDK::UExceptionWrapperSEH(GET_SYSTEM_EXCEPTION_DATA));
}
I=K;
}
else
{
++I;
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects by name ")+object_name+" FAILED! Object in use.");
}
}
if(Logger)
Logger->LogMessageEx(RDK_EX_DEBUG, __FUNCTION__, std::string("Destroy objects of class ")+object_class_name+std::string(" has finished: ")+sntoa(count)+std::string("/")+sntoa(size));
}
//
void UStorage::ClearObjectsStorage(bool force)
{
......@@ -680,7 +757,7 @@ void UStorage::ClearObjectsStorage(bool force)
FreeObjectsStorage(force);
}
//
//
void UStorage::ClearObjectsStorageByClass(const UId &classid)
{
UObjectsStorageIterator instances=ObjectsStorage.find(classid);
......@@ -945,11 +1022,17 @@ bool UStorage::AddClassToCollection(const std::string &new_class_name, const std
if(!lib->DelClass(new_class_name))
return false;
}
catch(UException &ex)
catch(EObjectStorageNotEmpty &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
return false;
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
catch(EClassIdNotExist &ex)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
//
// AddNewClass Logger
......@@ -996,10 +1079,16 @@ bool UStorage::DelClassFromCollection(const std::string &class_name, const std::
if(!library->DelClass(class_name))
return false;
}
catch(UException &ex)
catch(EObjectStorageNotEmpty &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
catch(EClassIdNotExist &ex)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
return true;
......@@ -1088,14 +1177,20 @@ bool UStorage::DeleteRuntimeCollection(const std::string &lib_name)
try
{
// DelClass()
// DelClass() (EObjectStorageNotEmpty EClassIdNotExist)
DelAbandonedClasses();
}
catch(UException &ex)
catch(EObjectStorageNotEmpty &ex)
{
if(Logger)
Logger->LogMessage(RDK_EX_DEBUG, __FUNCTION__, ex.what());
return false;
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
catch(EClassIdNotExist &ex)
{
if(Logger)
Logger->LogMessageEx(RDK_EX_ERROR, __FUNCTION__, ex.what());
return false;
}
return true;
}
......
......@@ -232,15 +232,18 @@ virtual int CalcNumObjects(void) const;
virtual int CalcNumObjects(const UId &classid) const;
virtual size_t CalcNumObjects(const string &classname) const;
//
//
/// force == true
virtual void FreeObjectsStorage(bool force=false);
//
virtual void FreeObjectsStorageByClass(const UId &classid);
//
/// force == true
virtual void ClearObjectsStorage(bool force=false);
//
//
virtual void ClearObjectsStorageByClass(const UId &classid);
// --------------------------
......
......@@ -121,6 +121,8 @@ UClassesListWidget::UClassesListWidget(QWidget *parent, RDK::UApplication *app)
connect(ui->actionDeleteClass, SIGNAL(triggered()), this, SLOT(DeleteClass()));
ui->listWidgetRTlibClasses->setContextMenuPolicy(Qt::ActionsContextMenu);
setAcceptDrops(true);
}
UClassesListWidget::~UClassesListWidget()
......@@ -171,6 +173,59 @@ void UClassesListWidget::SetModelScheme(UDrawEngineImageWidget* model)
ModelScheme = model;
}
void UClassesListWidget::dropEvent(QDropEvent *event)
{
/*
QByteArray itemData = event->mimeData()->data("ComponentName");
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
QString compname;
dataStream >> compname;
*/
//
QString lib = "";
QPoint globalPos = this->mapToGlobal(event->pos());
QPoint RTlibsPos = ui->listWidgetRTlibs->mapFromGlobal(globalPos);
QListWidgetItem* item = ui->listWidgetRTlibs->itemAt(RTlibsPos);
if(item)
lib = item->text();
AddNewClass(lib);
}
void UClassesListWidget::dragEnterEvent(QDragEnterEvent *event)
{
// QPoint globalPos = this->mapToGlobal(event->pos());
// QPoint GBoxLibsPos = ui->groupBoxLibList->mapFromGlobal(globalPos);
// QPoint GBoxCompsPos = ui->groupBoxLibComps->mapFromGlobal(globalPos);
if(event->mimeData()->hasFormat("ComponentName") && (ui->tabWidget->currentIndex() == 2))
// && (ui->groupBoxLibList->rect().contains(GBoxLibsPos) || ui->groupBoxLibComps->rect().contains(GBoxCompsPos)))
{
event->setDropAction(Qt::MoveAction);
event->accept();
}
else
{
event->ignore();
}
}
void UClassesListWidget::dragMoveEvent(QDragMoveEvent *event)
{
if(event->mimeData()->hasFormat("ComponentName") && (ui->tabWidget->currentIndex() == 2))
{
event->setDropAction(Qt::MoveAction);
event->accept();
}
else
{
event->ignore();
}
}
void UClassesListWidget::dragEvent(QModelIndex index)
{
QByteArray itemData;
......@@ -424,7 +479,11 @@ void UClassesListWidget::CreateRTlibrary()
{
std::string lib_name = dialog->GetLibName();
storage->CreateRuntimeCollection(lib_name);
if(!storage->CreateRuntimeCollection(lib_name))
{
QMessageBox::warning(this, "Error",
"An error occurred while creating library \"" + QString::fromStdString(dialog->GetLibName())+"\"");
}
AUpdateLibsView(QString::fromStdString(lib_name));
}
......@@ -453,7 +512,11 @@ void UClassesListWidget::DeleteRTlibrary()
if(dialog->exec() == QDialog::Accepted)
{
storage->DeleteRuntimeCollection(lib_name.toLocal8Bit().data());
if(!storage->DeleteRuntimeCollection(lib_name.toLocal8Bit().data()))
{
QMessageBox::warning(this, "Error",
"An error occurred while deleting library \"" + lib_name+"\"");
}
AUpdateLibsView("");
}
......@@ -461,7 +524,7 @@ void UClassesListWidget::DeleteRTlibrary()
}
void UClassesListWidget::AddNewClass()
void UClassesListWidget::AddNewClass(QString cur_lib)
{
RDK::UELockPtr<RDK::UEngine> engine=RDK::GetEngineLock();
......@@ -471,14 +534,14 @@ void UClassesListWidget::AddNewClass()
//
RDK::UEPtr<RDK::UContainer> container = engine->GetModel()
->GetComponent(ModelScheme->GetSelectedCmponent(), true);
->GetComponentL(ModelScheme->GetLongName(), true);
//
if(!container)
return;
// ( )
QString lib_name = "";
if(ui->listWidgetRTlibs->currentItem())
QString lib_name = cur_lib;
if(ui->listWidgetRTlibs->currentItem() && lib_name.isEmpty())
lib_name = ui->listWidgetRTlibs->currentItem()->text();
std::string buff;
......@@ -488,10 +551,14 @@ void UClassesListWidget::AddNewClass()
CrClassDialog* dialog = new CrClassDialog(libs_names, lib_name, QString::fromStdString(container->GetName()));
if(dialog->exec() == QDialog::Accepted)
{
engine->GetEnvironment()->
if(!engine->GetEnvironment()->
GetStorage()->AddClassToCollection(dialog->GetClassName(), dialog->GetCompName(),
dialog->GetReplace(), container, dialog->GetLibName());
dialog->GetReplace(), container, dialog->GetLibName()))
{
QMessageBox::warning(this, "Error",
"An error occurred while adding new class \"" + QString::fromStdString(dialog->GetClassName())
+ "\" to library \"" + QString::fromStdString(dialog->GetLibName()) +"\"");
}
AUpdateLibsView(QString::fromStdString(dialog->GetLibName()));
}
......@@ -524,7 +591,11 @@ void UClassesListWidget::DeleteClass()
if(dialog->exec() == QDialog::Accepted)
{
storage->DelClassFromCollection(class_name.toUtf8().data(), lib_name.toUtf8().data());
if(!storage->DelClassFromCollection(class_name.toUtf8().data(), lib_name.toUtf8().data()))
{
QMessageBox::warning(this, "Error",
"An error occurred while delecting class \"" + class_name +"\"");
}
AUpdateLibsView(lib_name);
}
......
......@@ -4,12 +4,14 @@
#include "UVisualControllerWidget.h"
#include "UDrawEngineImageWidget.h"
#include <QWidget>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QMouseEvent>
#include <QModelIndex>
#include <QListWidget>
#include <QDialog>
#include <QComboBox>
#include <QMessageBox>
namespace Ui {
class UClassesListWidget;
......@@ -38,6 +40,9 @@ public:
void SetModelScheme(UDrawEngineImageWidget* model);
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
public slots:
void dragEvent(QModelIndex index);
......@@ -65,7 +70,7 @@ public slots:
void DeleteRTlibrary();
///
void AddNewClass();
void AddNewClass(QString cur_lib = "");
void DeleteClass();
private:
......
......@@ -184,7 +184,15 @@ void UDrawEngineImageWidget::mousePressEvent(QMouseEvent *event)
emit componentSelected(myLongName());
reDrawScheme(false);
if(event->button() == Qt::RightButton)
{
contextMenu->popup(QWidget::mapToGlobal(event->pos()));
return;
}
if(QApplication::keyboardModifiers() == Qt::ControlModifier)
{
dragEvent();
return;
}
}
else
if((event->x() < 10 || event->y() < 10
......@@ -368,7 +376,7 @@ void UDrawEngineImageWidget::dropEvent(QDropEvent *event)
void UDrawEngineImageWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasFormat("Component"))
if(event->mimeData()->hasFormat("Component"))
{
event->setDropAction(Qt::MoveAction);
event->accept();
......@@ -381,7 +389,7 @@ void UDrawEngineImageWidget::dragEnterEvent(QDragEnterEvent *event)
void UDrawEngineImageWidget::dragMoveEvent(QDragMoveEvent *event)
{
if (event->mimeData()->hasFormat("Component"))
if(event->mimeData()->hasFormat("Component"))
{
event->setDropAction(Qt::MoveAction);
event->accept();
......@@ -392,6 +400,22 @@ void UDrawEngineImageWidget::dragMoveEvent(QDragMoveEvent *event)
}
}
void UDrawEngineImageWidget::dragEvent()
{
QByteArray itemData;
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
dataStream << QString::fromStdString(GetLongName());
QMimeData *mimeData = new QMimeData();
mimeData->setData("ComponentName", itemData);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction, Qt::CopyAction);
}
void UDrawEngineImageWidget::resizeEvent(QResizeEvent *)
{
reDrawScheme(false,true);
......@@ -710,10 +734,7 @@ void UDrawEngineImageWidget::SetApplication(RDK::UApplication *app)
}
///
std::string UDrawEngineImageWidget::GetSelectedCmponent()
const std::string UDrawEngineImageWidget::GetLongName()
{
if(!selectedComponent.empty())
return selectedComponent;
else
return std::string();
return myLongName().toUtf8().data();
}
......@@ -8,6 +8,7 @@
#include <QMouseEvent>
#include <QContextMenuEvent>
#include <QDropEvent>
#include <QDrag>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QMenu>
......@@ -37,6 +38,8 @@ public:
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragEvent();
//
void resizeEvent(QResizeEvent*);
......@@ -56,7 +59,7 @@ public:
void SetApplication(RDK::UApplication *app);
///
std::string GetSelectedCmponent();
const std::string GetLongName();
public slots:
//
......
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