Skip to content

Commit

Permalink
- Fixed some problems of file dropping feature.
Browse files Browse the repository at this point in the history
- Now user can select multiple files and drop them on OMEdit.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9529 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Jul 24, 2011
1 parent 68b2d75 commit 867af12
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 199 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Helper.cpp
Expand Up @@ -216,7 +216,7 @@ QString GUIMessages::getMessage(int type)
case PLOT_PARAMETRIC_DIFF_FILES:
return "You cannot do a plot parametric between two different simulation result files. Make sure you select two variables from the same simulation result file.";
case FILE_FORMAT_NOT_SUPPORTED:
return "The file format is not supported. You can only open .mo files here.";
return "The file '%1' is not a valid Modelica file. The file format is not supported. You can only open .mo files here.";
case INCORRECT_HTML_TAGS:
return "The html tags in the documentation are incorrect. Give correct starting and ending html tags and save it again.";
case ITEM_DROPPED_ON_ITSELF:
Expand Down
33 changes: 4 additions & 29 deletions OMEdit/OMEditGUI/LibraryWidget.cpp
Expand Up @@ -238,6 +238,7 @@ void ModelicaTree::addNode(QString name, int type, QString parentName, QString p
newTreePost->setIcon(0, QIcon(libComponent->getComponentPixmap(Helper::iconSize)));

mpParentLibraryWidget->addModelicaComponentObject(libComponent);
mpParentLibraryWidget->mpParentMainWindow->mpStatusBar->clearMessage();
}

void ModelicaTree::openProjectTab(QTreeWidgetItem *item, int column)
Expand Down Expand Up @@ -708,30 +709,6 @@ void LibraryTree::loadModelicaLibraryHierarchy(QString value, QString prefixStr)
addNodes(tempPackageNodesList);
addNodes(tempNonPackageNodesList);
}

/*
Open the Following code and comment the above if loading library once.
*/

// if (this->mpParentMainWindow->mpOMCProxy->isPackage(prefixStr + value))
// {
// //if value is Modelica then dont send it to addClass. Because we already added it statically.
// if (value != tr("Modelica"))
// {
// this->mpParentMainWindow->statusBar->showMessage(QString("Loading: ").append(prefixStr + value));
// addClass(value, StringHandler::getSubStringFromDots(prefixStr), prefixStr);
// }
// QStringList list = this->mpParentMainWindow->mpOMCProxy->getClassNames(prefixStr + value);
// prefixStr += value + ".";
// foreach (QString str, list)
// {
// loadModelicaLibraryHierarchy(str, prefixStr);
// }
// }
// else
// {
// addClass(value, StringHandler::getSubStringFromDots(prefixStr), prefixStr);
// }
}

//! Let the user to point out a OM Class and adds it to the library widget.
Expand Down Expand Up @@ -1354,15 +1331,13 @@ void LibraryWidget::addModelFiles(QString fileName, QString parentFileName, QStr
{
if (parentFileName.isEmpty())
{
this->addModelicaNode(fileName, mpParentMainWindow->mpOMCProxy->getClassRestriction(fileName),
parentFileName, parentStructure);
this->addModelicaNode(fileName, mpParentMainWindow->mpOMCProxy->getClassRestriction(fileName), parentFileName, parentStructure);
parentStructure = fileName;

}
else
{
this->addModelicaNode(fileName, mpParentMainWindow->mpOMCProxy->getClassRestriction(parentStructure),
parentFileName, StringHandler::removeLastWordAfterDot(parentStructure).append("."));
this->addModelicaNode(fileName, mpParentMainWindow->mpOMCProxy->getClassRestriction(parentStructure), parentFileName,
StringHandler::removeLastWordAfterDot(parentStructure).append("."));
}

if (this->mpParentMainWindow->mpOMCProxy->isPackage(parentStructure))
Expand Down
200 changes: 89 additions & 111 deletions OMEdit/OMEditGUI/ProjectTabWidget.cpp
Expand Up @@ -148,23 +148,18 @@ void GraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
//! @param event contains information of the drag operation.
void GraphicsView::dragMoveEvent(QDragMoveEvent *event)
{

// check if the view is readonly or not
if (mpParentProjectTab->isReadOnly())
{
event->ignore();
return;
}



if (event->mimeData()->hasFormat("image/modelica-component") || event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileName\""))
if (event->mimeData()->hasFormat("image/modelica-component") || event->mimeData()->hasFormat("text/uri-list"))
{
event->setDropAction(Qt::CopyAction);
event->accept();
}


else
{
event->ignore();
Expand All @@ -177,138 +172,121 @@ void GraphicsView::dropEvent(QDropEvent *event)
{
this->setFocus();


// check if the view is readonly or not
if (mpParentProjectTab->isReadOnly())
{
event->ignore();
return;
}




if (!event->mimeData()->hasFormat("image/modelica-component") && !event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileName\""))
if (!event->mimeData()->hasFormat("image/modelica-component") && !event->mimeData()->hasFormat("text/uri-list"))
{
event->ignore();

return;
}


else

{

if(event->mimeData()->hasFormat("application/x-qt-windows-mime;value=\"FileName\""))
{

QByteArray itemData = event->mimeData()->data("application/x-qt-windows-mime;value=\"FileNameW\"");
QString filename = QString::fromUtf16((ushort*)itemData.data(), itemData.size() / 2);



filename=filename.trimmed();




if(filename.contains(".mo",Qt::CaseInsensitive))
if (event->mimeData()->hasFormat("text/uri-list"))
{
int i = filename.indexOf(".mo",0,Qt::CaseInsensitive);
filename = filename.left(i+3);
mpParentProjectTab->mpParentProjectTabWidget->openFile(filename);
event->accept();
bool fileOpened = false;
foreach (QUrl fileUrl, event->mimeData()->urls())
{
QFileInfo fileInfo(fileUrl.toLocalFile());
if (fileInfo.suffix().compare("mo", Qt::CaseInsensitive) == 0)
{
mpParentProjectTab->mpParentProjectTabWidget->openFile(fileInfo.absoluteFilePath());
fileOpened = true;
}
else
{
QString message = QString(GUIMessages::getMessage(GUIMessages::FILE_FORMAT_NOT_SUPPORTED).arg(fileInfo.fileName()));
mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->mpMessageWidget->printGUIErrorMessage(message);
}
}
// if one file is valid and opened then accept the event
if (fileOpened)
{
event->accept();
return;
}
// if all files are invalid Modelica files ignore the event.
else
{
event->ignore();
return;
}
}

else
{
QByteArray itemData = event->mimeData()->data("image/modelica-component");
QDataStream dataStream(&itemData, QIODevice::ReadOnly);

QString message = QString(GUIMessages::getMessage(GUIMessages::FILE_FORMAT_NOT_SUPPORTED));
mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->mpMessageWidget->printGUIErrorMessage(message);


event->ignore();

return;

}


}
else
{
QByteArray itemData = event->mimeData()->data("image/modelica-component");
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
QString name, classname;
int type;
QPointF point (mapToScene(event->pos()));
dataStream >> name >> classname >> type;

QString name, classname;
int type;
QPointF point (mapToScene(event->pos()));
dataStream >> name >> classname >> type;
MainWindow *pMainWindow = mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow;

MainWindow *pMainWindow = mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow;

//item not to be dropped on itself
name = StringHandler::getLastWordAfterDot(name);
if(name!=mpParentProjectTab->mModelName)
{
name = getUniqueComponentName(name.toLower());
// if dropping an item on the diagram layer
if (mIconType == StringHandler::DIAGRAM)
{
// if item is a class, model, block, connector or record. then we can drop it to the graphicsview
if ((type == StringHandler::CLASS) or (type == StringHandler::MODEL) or (type == StringHandler::BLOCK) or
(type == StringHandler::CONNECTOR) or (type == StringHandler::RECORD))
{
if (type == StringHandler::CONNECTOR)
//item not to be dropped on itself
name = StringHandler::getLastWordAfterDot(name);
if(name!=mpParentProjectTab->mModelName)
{
addComponentoView(name, classname, point, true, true, true);
mpParentProjectTab->mpIconGraphicsView->addComponentoView(name, classname, point, true, false);
name = getUniqueComponentName(name.toLower());
// if dropping an item on the diagram layer
if (mIconType == StringHandler::DIAGRAM)
{
// if item is a class, model, block, connector or record. then we can drop it to the graphicsview
if ((type == StringHandler::CLASS) or (type == StringHandler::MODEL) or (type == StringHandler::BLOCK) or
(type == StringHandler::CONNECTOR) or (type == StringHandler::RECORD))
{
if (type == StringHandler::CONNECTOR)
{
addComponentoView(name, classname, point, true, true, true);
mpParentProjectTab->mpIconGraphicsView->addComponentoView(name, classname, point, true, false);
}
else
{
addComponentoView(name, classname, point);
}
event->accept();
}
else
{
pMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::DIAGRAM_VIEW_DROP_MSG)
.arg(classname)
.arg(StringHandler::getModelicaClassType(type)));
event->ignore();
}
}
// if dropping an item on the icon layer
else if (mIconType == StringHandler::ICON)
{
// if item is a connector. then we can drop it to the graphicsview
if (type == StringHandler::CONNECTOR)
{
addComponentoView(name, classname, point, true, false);
mpParentProjectTab->mpDiagramGraphicsView->addComponentoView(name, classname, point, true,
true, true);
event->accept();
}
else
{
pMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::ICON_VIEW_DROP_MSG)
.arg(classname)
.arg(StringHandler::getModelicaClassType(type)));
event->ignore();
}
}
}
//if dropping an item on itself
else
{
addComponentoView(name, classname, point);
pMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::ITEM_DROPPED_ON_ITSELF));
event->ignore();
}
event->accept();
}
else
{
pMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::DIAGRAM_VIEW_DROP_MSG)
.arg(classname)
.arg(StringHandler::getModelicaClassType(type)));
event->ignore();
}
}
// if dropping an item on the icon layer
else if (mIconType == StringHandler::ICON)
{
// if item is a connector. then we can drop it to the graphicsview
if (type == StringHandler::CONNECTOR)
{
addComponentoView(name, classname, point, true, false);
mpParentProjectTab->mpDiagramGraphicsView->addComponentoView(name, classname, point, true,
true, true);
event->accept();
}
else
{
pMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::ICON_VIEW_DROP_MSG)
.arg(classname)
.arg(StringHandler::getModelicaClassType(type)));
event->ignore();
}
}
}
//if dropping an item on itself
else
{

pMainWindow->mpMessageWidget->printGUIInfoMessage(GUIMessages::getMessage(GUIMessages::ITEM_DROPPED_ON_ITSELF)
);
event->ignore();
}
}
}
}

void GraphicsView::addComponentoView(QString name, QString className, QPointF point, bool isConnector,
Expand Down

0 comments on commit 867af12

Please sign in to comment.