diff --git a/qucs/qucs/CMakeLists.txt b/qucs/qucs/CMakeLists.txt
index 8294b592ab..54472ee270 100755
--- a/qucs/qucs/CMakeLists.txt
+++ b/qucs/qucs/CMakeLists.txt
@@ -112,7 +112,7 @@ SET(QUCS_SRCS
mouseactions.cpp qucs_actions.cpp schematic_file.cpp
wirelabel.cpp node.cpp qucs_init.cpp
syntax.cpp misc.cpp messagedock.cpp
- imagewriter.cpp printerwriter.cpp
+ imagewriter.cpp printerwriter.cpp projectView.cpp
)
SET(QUCS_HDRS
diff --git a/qucs/qucs/Makefile.am b/qucs/qucs/Makefile.am
index 9959aa6e6a..4d332c94e1 100644
--- a/qucs/qucs/Makefile.am
+++ b/qucs/qucs/Makefile.am
@@ -39,7 +39,8 @@ qucs_SOURCES = node.cpp element.cpp qucsdoc.cpp wire.cpp mouseactions.cpp \
qucs.cpp main.cpp wirelabel.cpp qucs_init.cpp qucs_actions.cpp \
viewpainter.cpp mnemo.cpp schematic.cpp schematic_element.cpp textdoc.cpp \
schematic_file.cpp syntax.cpp module.cpp octave_window.cpp qrc_qucs.cpp \
- messagedock.cpp misc.cpp imagewriter.cpp printerwriter.cpp
+ messagedock.cpp misc.cpp imagewriter.cpp printerwriter.cpp \
+ projectView.cpp
qrc_qucs.cpp: qucs.qrc
$(RCC) -o $@ $<
diff --git a/qucs/qucs/dialogs/librarydialog.cpp b/qucs/qucs/dialogs/librarydialog.cpp
index 274dbf99ad..8cb375f366 100644
--- a/qucs/qucs/dialogs/librarydialog.cpp
+++ b/qucs/qucs/dialogs/librarydialog.cpp
@@ -1,19 +1,25 @@
-/***************************************************************************
- librarydialog.cpp
- -------------------
- begin : Sun Jun 04 2006
- copyright : (C) 2006 by Michael Margraf
- email : michael.margraf@alumni.tu-berlin.de
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
+/*
+ * librarydialog.cpp - implementation of dialog to create library
+ *
+ * Copyright (C) 2006, Michael Margraf, michael.margraf@alumni.tu-berlin.de
+ * Copyright (C) 2014, Yodalee, lc85301@gmail.com
+ *
+ * This file is part of Qucs
+ *
+ * Qucs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qucs. If not, see .
+ *
+ */
#ifdef HAVE_CONFIG_H
# include
@@ -36,18 +42,17 @@
#include
#include
#include
+#include
#include "librarydialog.h"
-#include "qucs.h"
#include "main.h"
#include "schematic.h"
extern SubMap FileList;
-LibraryDialog::LibraryDialog(QucsApp *App_, QTreeWidgetItem *SchematicList)
- : QDialog(App_)
+LibraryDialog::LibraryDialog(QWidget *parent)
+ : QDialog(parent)
{
- App = App_;
setWindowTitle(tr("Create Library"));
Expr.setPattern("[\\w_]+");
@@ -90,7 +95,7 @@ LibraryDialog::LibraryDialog(QucsApp *App_, QTreeWidgetItem *SchematicList)
QWidget *scrollWidget = new QWidget();
- QVBoxLayout *checkBoxLayout = new QVBoxLayout();
+ checkBoxLayout = new QVBoxLayout();
scrollWidget->setLayout(checkBoxLayout);
scrollArea->setWidget(scrollWidget);
@@ -204,26 +209,6 @@ LibraryDialog::LibraryDialog(QucsApp *App_, QTreeWidgetItem *SchematicList)
hbox2->addWidget(close);
connect(close, SIGNAL(clicked()), SLOT(reject()));
msgLayout->addLayout(hbox2);
-
- // ...........................................................
- // insert all subcircuits of into checklist
- QTreeWidgetItem *p ;
- for(int i=0; i < SchematicList->childCount(); i++){
- p = SchematicList->child(i);
- if(p->parent() == 0)
- break;
- if(!p->text(1).isEmpty()){
- QCheckBox *subCheck = new QCheckBox(p->text(0));
- checkBoxLayout->addWidget(subCheck);
- BoxList.append(subCheck);
- }
- }
-
- if(BoxList.isEmpty()) {
- ButtCreateNext->setEnabled(false);
- QLabel *noProj = new QLabel(tr("No projects!"));
- checkBoxLayout->addWidget(noProj);
- }
}
@@ -233,6 +218,24 @@ LibraryDialog::~LibraryDialog()
delete Validator;
}
+void
+LibraryDialog::fillSchematicList(QStringList SchematicList)
+{
+ // ...........................................................
+ // insert all subcircuits of into checklist
+ if (SchematicList.size() == 0) {
+ ButtCreateNext->setEnabled(false);
+ QLabel *noProj = new QLabel(tr("No projects!"));
+ checkBoxLayout->addWidget(noProj);
+ } else {
+ foreach(const QString &filename, SchematicList) {
+ QCheckBox *subCheck = new QCheckBox(filename);
+ checkBoxLayout->addWidget(subCheck);
+ BoxList.append(subCheck);
+ }
+ }
+}
+
// ---------------------------------------------------------------
void LibraryDialog::slotCreateNext()
{
diff --git a/qucs/qucs/dialogs/librarydialog.h b/qucs/qucs/dialogs/librarydialog.h
index c68e27a328..05950c6968 100644
--- a/qucs/qucs/dialogs/librarydialog.h
+++ b/qucs/qucs/dialogs/librarydialog.h
@@ -1,19 +1,25 @@
-/***************************************************************************
- librarydialog.h
- -----------------
- begin : Sun Jun 04 2006
- copyright : (C) 2006 by Michael Margraf
- email : michael.margraf@alumni.tu-berlin.de
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
+/*
+ * librarydialog.h - declaration of dialog to create library
+ *
+ * Copyright (C) 2006, Michael Margraf, michael.margraf@alumni.tu-berlin.de
+ * Copyright (C) 2014, Yodalee, lc85301@gmail.com
+ *
+ * This file is part of Qucs
+ *
+ * Qucs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qucs. If not, see .
+ *
+ */
#ifndef LIBRARYDIALOG_H
#define LIBRARYDIALOG_H
@@ -32,7 +38,6 @@
#include
class QLabel;
-class QucsApp;
class QLineEdit;
class QTextEdit;
class QPushButton;
@@ -41,14 +46,17 @@ class QTreeWidgetItem;
class QGroupBox;
class QRegExpValidator;
class QStackedWidget;
+class QStringList;
class LibraryDialog : public QDialog {
Q_OBJECT
public:
- LibraryDialog(QucsApp*, QTreeWidgetItem*);
+ LibraryDialog(QWidget *);
~LibraryDialog();
+ void fillSchematicList(QStringList);
+
private slots:
void slotCreateNext();
void slotSave();
@@ -66,6 +74,7 @@ private slots:
private:
int curDescr;
QVBoxLayout *all; // the mother of all widgets
+ QVBoxLayout *checkBoxLayout;
QStackedWidget *stackedWidgets;
QLabel *theLabel;
QLabel *checkedCktName;
@@ -82,7 +91,6 @@ private slots:
QStringList Descriptions;
QCheckBox *checkDescr;
- QucsApp *App;
QFile LibFile;
QDir LibDir;
QRegExp Expr;
diff --git a/qucs/qucs/dialogs/qucssettingsdialog.cpp b/qucs/qucs/dialogs/qucssettingsdialog.cpp
index e8fd756627..8ad9d01bf2 100644
--- a/qucs/qucs/dialogs/qucssettingsdialog.cpp
+++ b/qucs/qucs/dialogs/qucssettingsdialog.cpp
@@ -594,7 +594,7 @@ void QucsSettingsDialog::slotApply()
if(changed)
{
App->readProjects();
- App->readProjectFiles();
+ App->slotUpdateTreeview();
App->repaint();
}
diff --git a/qucs/qucs/dialogs/searchdialog.cpp b/qucs/qucs/dialogs/searchdialog.cpp
index 4b3757ee30..5f1c7a3f10 100644
--- a/qucs/qucs/dialogs/searchdialog.cpp
+++ b/qucs/qucs/dialogs/searchdialog.cpp
@@ -1,5 +1,5 @@
/*
- * searchdialog.h - implementation of search dialog
+ * searchdialog.cpp - implementation of search dialog
*
* Copyright (C) 2006, Michael Margraf, michael.margraf@alumni.tu-berlin.de
* Copyright (C) 2014, Yodalee, lc85301@gmail.com
diff --git a/qucs/qucs/projectView.cpp b/qucs/qucs/projectView.cpp
new file mode 100644
index 0000000000..d5deadec32
--- /dev/null
+++ b/qucs/qucs/projectView.cpp
@@ -0,0 +1,162 @@
+/*
+ * ProjectView.cpp - implementation of project model
+ * the model manage the files in project directory
+ *
+ * Copyright (C) 2014, Yodalee, lc85301@gmail.com
+ *
+ * This file is part of Qucs
+ *
+ * Qucs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qucs. If not, see .
+ *
+ */
+
+#include "projectView.h"
+#include "schematic.h"
+
+#include
+#include
+#include
+#include
+
+ProjectView::ProjectView(QWidget *parent)
+ : QTreeView(parent)
+{
+ m_projPath = QString();
+ m_projPath = QString();
+ m_valid = false;
+ m_model = new QStandardItemModel(8, 2, this);
+
+ refresh();
+
+ this->setModel(m_model);
+ this->setEditTriggers(QAbstractItemView::NoEditTriggers);
+}
+
+ProjectView::~ProjectView()
+{
+ delete m_model;
+}
+
+void
+ProjectView::setProjPath(const QString &path)
+{
+ m_valid = !path.isEmpty() && QDir(path).exists();
+
+ if (m_valid) {
+ //test path exist
+ m_projPath = path;
+ m_projName = path;
+
+ // cut off trailing '/'
+ if (m_projName.endsWith(QDir::separator())) {
+ m_projName.chop(1);
+ }
+ int i = m_projName.lastIndexOf(QDir::separator());
+ if(i > 0) {
+ m_projName = m_projName.mid(i+1); // cut out the last subdirectory
+ }
+ m_projName.remove("_prj");
+ }
+ refresh();
+}
+
+// refresh using projectPath
+void
+ProjectView::refresh()
+{
+ m_model->clear();
+
+ QStringList header;
+ header << tr("Content of %1").arg(m_projName) << tr("Note");
+ m_model->setHorizontalHeaderLabels(header);
+
+ APPEND_ROW(m_model, FILETYPE1);
+ APPEND_ROW(m_model, FILETYPE2);
+ APPEND_ROW(m_model, FILETYPE3);
+ APPEND_ROW(m_model, FILETYPE4);
+ APPEND_ROW(m_model, FILETYPE5);
+ APPEND_ROW(m_model, FILETYPE6);
+ APPEND_ROW(m_model, FILETYPE7);
+ APPEND_ROW(m_model, FILETYPE8);
+
+ setExpanded(m_model->index(6, 0), true);
+
+ if (!m_valid) {
+ return;
+ }
+
+ // put all files into "Content"-ListView
+ QDir workPath(m_projPath);
+ QStringList files = workPath.entryList("*", QDir::Files, QDir::Name);
+ QStringList::iterator it;
+ QString extName, fileName;
+ QList columnData;
+
+#define APPEND_CHILD(category, data) \
+ m_model->item(category, 0)->appendRow(data);
+
+ for(it = files.begin(); it != files.end(); ++it) {
+ fileName = (*it).toAscii();
+ extName = QFileInfo(workPath.filePath(fileName)).completeSuffix();
+
+ columnData.clear();
+ columnData.append(new QStandardItem(fileName));
+
+ if(extName == "dat") {
+ APPEND_CHILD(0, columnData);
+ }
+ else if(extName == "dpl") {
+ APPEND_CHILD(1, columnData);
+ }
+ else if(extName == "v") {
+ APPEND_CHILD(2, columnData);
+ }
+ else if(extName == "va") {
+ APPEND_CHILD(3, columnData);
+ }
+ else if((extName == "vhdl") || (extName == "vhd")) {
+ APPEND_CHILD(4, columnData);
+ }
+ else if((extName == "m") || (extName == "oct")) {
+ APPEND_CHILD(5, columnData);
+ }
+ else if(extName == "sch") {
+ int n = Schematic::testFile(workPath.filePath(fileName));
+ if(n >= 0) {
+ if(n > 0) {
+ columnData.append(new QStandardItem(QString::number(n)+tr("-port")));
+ }
+ }
+ APPEND_CHILD(6, columnData);
+ }
+ else {
+ APPEND_CHILD(7, columnData);
+ }
+ }
+
+ resizeColumnToContents(0);
+}
+
+QStringList
+ProjectView::exportSchematic()
+{
+ QStringList list;
+ QStandardItem *item = m_model->item(6, 0);
+ for (int i = 0; i < item->rowCount(); ++i) {
+ if (item->child(i,1)) {
+ list.append(item->child(i,0)->text());
+ }
+ }
+ return list;
+}
diff --git a/qucs/qucs/projectView.h b/qucs/qucs/projectView.h
new file mode 100644
index 0000000000..a3e20d4777
--- /dev/null
+++ b/qucs/qucs/projectView.h
@@ -0,0 +1,68 @@
+/*
+ * projectView.h - declaration of project view
+ * and the model that manage files in project
+ *
+ * Copyright (C) 2014, Yodalee, lc85301@gmail.com
+ *
+ * This file is part of Qucs
+ *
+ * Qucs is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Qucs. If not, see .
+ *
+ */
+
+#ifndef PROJECTVIEW_H_
+#define PROJECTVIEW_H_ value
+
+#include
+#include
+
+#define FILETYPE1 tr("Datasets")
+#define FILETYPE2 tr("Data Displays")
+#define FILETYPE3 tr("Verilog")
+#define FILETYPE4 tr("Verilog-A")
+#define FILETYPE5 tr("VHDL")
+#define FILETYPE6 tr("Octave")
+#define FILETYPE7 tr("Schematics")
+#define FILETYPE8 tr("Others")
+
+#define APPEND_ROW(parent, data) \
+({ \
+ QList c; \
+ c.append(new QStandardItem(data)); \
+ parent->appendRow(c); \
+})
+
+class QStandardItemModel;
+
+class ProjectView : public QTreeView
+{
+public:
+ ProjectView (QWidget *parent);
+ virtual ~ProjectView ();
+
+ QStandardItemModel *model() { return m_model; };
+
+ //data related
+ void setProjPath(const QString &);
+ void refresh();
+ QStringList exportSchematic();
+private:
+ QStandardItemModel *m_model;
+
+ bool m_valid;
+ QString m_projPath;
+ QString m_projName;
+};
+
+#endif /* PROJECTVIEW_H_ */
diff --git a/qucs/qucs/qucs.cpp b/qucs/qucs/qucs.cpp
index fd29373c5f..2bc6e6e968 100644
--- a/qucs/qucs/qucs.cpp
+++ b/qucs/qucs/qucs.cpp
@@ -51,6 +51,7 @@
#include "messagedock.h"
#include "wire.h"
#include "module.h"
+#include "projectView.h"
#include "components/components.h"
#include "paintings/paintings.h"
#include "diagrams/diagrams.h"
@@ -189,30 +190,6 @@ QucsApp::~QucsApp()
// ########## Creates the working area (QTabWidget etc.) ##########
// ########## ##########
// #######################################################################
-void QucsApp::initContentListView()
-{
-
- Content->clear();
-
- ConOthers = new QTreeWidgetItem(Content);
- ConOthers->setText(0, tr("Others"));
- ConDatasets = new QTreeWidgetItem(Content);
- ConDatasets->setText(0, tr("Datasets"));
- ConDisplays = new QTreeWidgetItem(Content);
- ConDisplays->setText(0, tr("Data Displays"));
- ConOctave = new QTreeWidgetItem(Content);
- ConOctave->setText(0, tr("Octave"));
- ConVerilog = new QTreeWidgetItem(Content);
- ConVerilog->setText(0, tr("Verilog"));
- ConVerilogA = new QTreeWidgetItem(Content);
- ConVerilogA->setText(0, tr("Verilog-A"));
- ConSources = new QTreeWidgetItem(Content);
- ConSources->setText(0, tr("VHDL"));
- ConSchematics = new QTreeWidgetItem(Content);
- ConSchematics->setText(0, tr("Schematics"));
-
-}
-
/**
* @brief QucsApp::initView Setup the layour of all widgets
*/
@@ -292,27 +269,17 @@ void QucsApp::initView()
// ----------------------------------------------------------
// "Content" Tab of the left QTabWidget
- Content = new QTreeWidget(this);
- Content->setColumnCount(2);
- QStringList headers;
- headers << tr("Content of") << tr("Note");
- Content->setHeaderLabels(headers);
- Content->setSortingEnabled(false);
- Content->setColumnWidth(0,150);
-
- // allow for a custom context menu
+ Content = new ProjectView(this);
Content->setContextMenuPolicy(Qt::CustomContextMenu);
- initContentListView();
-
- TabView->addTab(Content,tr("Content"));
+ TabView->addTab(Content, tr("Content"));
TabView->setTabToolTip(TabView->indexOf(Content), tr("content of current project"));
- connect(Content, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
- SLOT(slotOpenContent(QTreeWidgetItem*)));
+ connect(Content, SIGNAL(clicked(const QModelIndex &)),
+ SLOT(slotSelectSubcircuit(const QModelIndex &)));
- connect(Content, SIGNAL(itemPressed(QTreeWidgetItem*, int)),
- SLOT(slotSelectSubcircuit(QTreeWidgetItem*)));
+ connect(Content, SIGNAL(doubleClicked(const QModelIndex &)),
+ SLOT(slotOpenContent(const QModelIndex &)));
// ----------------------------------------------------------
// "Component" Tab of the left QTabWidget
@@ -365,6 +332,7 @@ void QucsApp::initView()
libTreeWidget = new QTreeWidget (this);
libTreeWidget->setColumnCount (1);
+ QStringList headers;
headers.clear ();
headers << tr ("Libraries");
libTreeWidget->setHeaderLabels (headers);
@@ -898,313 +866,208 @@ void QucsApp::slotSelectComponent(QListWidgetItem *item)
void QucsApp::initCursorMenu()
{
-
- // TODO -> The contentmenu is also shown when the user right-clicks on a category...
ContentMenu = new QMenu(this);
-
- ActionCMenuOpen = new QAction(tr("Open"), ContentMenu);
- connect(ActionCMenuOpen, SIGNAL(triggered()), this, SLOT(slotCMenuOpen()));
- ContentMenu->addAction(ActionCMenuOpen);
-
- ActionCMenuCopy = new QAction(tr("Duplicate"), ContentMenu);
- connect(ActionCMenuCopy, SIGNAL(triggered()), this, SLOT(slotCMenuCopy()));
- ContentMenu->addAction(ActionCMenuCopy);
-
- ActionCMenuRename = new QAction(tr("Rename"), ContentMenu);
- connect(ActionCMenuRename, SIGNAL(triggered()), this, SLOT(slotCMenuRename()));
- ContentMenu->addAction(ActionCMenuRename);
-
- ActionCMenuDelete = new QAction(tr("Delete"), ContentMenu);
- connect(ActionCMenuDelete, SIGNAL(triggered()), this, SLOT(slotCMenuDelete()));
- ContentMenu->addAction(ActionCMenuDelete);
-
- ActionCMenuInsert = new QAction(tr("Insert"), ContentMenu);
- connect(ActionCMenuInsert, SIGNAL(triggered()), this, SLOT(slotCMenuInsert()));
- ContentMenu->addAction(ActionCMenuInsert);
-
-
- // TODO -> not implemented yet...
- //ActionCMenuDelGroup = new QAction(tr("Delete Group"), ContentMenu);
- //connect(ActionCMenuDelGroup, SIGNAL(triggered()), this, SLOT(slotCMenuDelGroup()));
- //Content->addAction(ActionCMenuDelGroup);
-
-
+#define APPEND_MENU(action, slot, text) \
+ { \
+ action = new QAction(tr(text), ContentMenu); \
+ connect(action, SIGNAL(triggered()), SLOT(slot())); \
+ ContentMenu->addAction(action); \
+ }
+
+ APPEND_MENU(ActionCMenuOpen, slotCMenuOpen, "Open")
+ APPEND_MENU(ActionCMenuCopy, slotCMenuCopy, "Duplicate")
+ APPEND_MENU(ActionCMenuRename, slotCMenuRename, "Rename")
+ APPEND_MENU(ActionCMenuDelete, slotCMenuDelete, "Delete")
+ APPEND_MENU(ActionCMenuInsert, slotCMenuInsert, "Insert")
+
+#undef APPEND_MENU
connect(Content, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(slotShowContentMenu(const QPoint&)));
}
// ----------------------------------------------------------
// Shows the menu.
-void QucsApp::slotShowContentMenu(const QPoint& pos) {
-
- QTreeWidgetItem *item = Content->currentItem();
- if(item->text(1 ).contains(tr("-port")))
- {
- ActionCMenuInsert->setVisible(true);
- }
- else
- {
- ActionCMenuInsert->setVisible(false);
- }
-
- // only show contentmenu when child is selected...
- if(item->parent()!= 0) {
+void QucsApp::slotShowContentMenu(const QPoint& pos)
+{
+ QModelIndex idx = Content->indexAt(pos);
+ if (idx.isValid() && idx.parent().isValid()) {
+ ActionCMenuInsert->setVisible(
+ idx.sibling(idx.row(), 1).data().toString().contains(tr("-port"))
+ );
ContentMenu->popup(Content->mapToGlobal(pos));
- }
-
+ }
}
-/* OLD Version
-void QucsApp::slotShowContentMenu(Q3ListViewItem *item, const QPoint& point, int)
+
+// ----------------------------------------------------------
+QString QucsApp::fileType (const QString& Ext)
{
- if(item)
- if(item->parent() != 0) { // no component, but item "schematic", ...
- if(item->parent()->nextSibling()) // "Others" section in listview ?
- ContentMenu->setItemEnabled(ContentMenu->idAt(3), true);
- else
- ContentMenu->setItemEnabled(ContentMenu->idAt(3), false);
- ContentMenu->popup(point);
- }
+ QString Type = tr("unknown");
+ if (Ext == "v")
+ Type = tr("Verilog source");
+ else if (Ext == "va")
+ Type = tr("Verilog-A source");
+ else if (Ext == "vhd" || Ext == "vhdl")
+ Type = tr("VHDL source");
+ else if (Ext == "dat")
+ Type = tr("data file");
+ else if (Ext == "dpl")
+ Type = tr("data display");
+ else if (Ext == "sch")
+ Type = tr("schematic");
+ else if (Ext == "sym")
+ Type = tr("symbol");
+ else if (Ext == "vhdl.cfg" || Ext == "vhd.cfg")
+ Type = tr("VHDL configuration");
+ else if (Ext == "cfg")
+ Type = tr("configuration");
+ return Type;
}
-*/
-// ----------------------------------------------------------
+
void QucsApp::slotCMenuOpen()
{
- QTreeWidgetItem *Item = Content->currentItem();
- if(Item == 0) return;
-
- slotOpenContent(Item);
+ slotOpenContent(Content->currentIndex());
}
-// ----------------------------------------------------------
void QucsApp::slotCMenuCopy()
{
- QTreeWidgetItem *Item = Content->currentItem();
- if(Item == 0) return;
+ QModelIndex idx = Content->currentIndex();
+
+ //test the item is valid
+ if (!idx.isValid() || !idx.parent().isValid()) { return; }
- QString Name = Item->text(0);
- QString currentPath = QucsSettings.QucsWorkDir.filePath(Name);
- QString Path = currentPath.section(QDir::separator(), 0, -2);
+ QString filename = idx.sibling(idx.row(), 0).data().toString();
+ QDir dir(QucsSettings.QucsWorkDir);
+ QString file(dir.filePath(filename));
+ QFileInfo fileinfo(file);
//check changed file save
int z = 0; //search if the doc is loaded
- QucsDoc *d = findDoc(currentPath, &z);
+ QucsDoc *d = findDoc(file, &z);
if (d != NULL && d->DocChanged) {
DocumentTab->setCurrentPage(z);
int ret = QMessageBox::question(this, tr("Copying Qucs document"),
- tr("The document contains unsaved changes!\n") +
- tr("Do you want to save the changes before copying?"),
- tr("&Ignore"), tr("&Save"), 0, 1);
+ tr("The document contains unsaved changes!\n") +
+ tr("Do you want to save the changes before copying?"),
+ tr("&Ignore"), tr("&Save"), 0, 1);
if (ret == 1) {
d->save();
}
}
- QString Suffix = Name.section('.',-1); // remember suffix
- QString Base = Name.section('.',0,-2);
- if(Base.isEmpty()) Base = Name;
+ QString suffix = fileinfo.completeSuffix();
+ QString base = fileinfo.baseName();
+ if(base.isEmpty()) {
+ base = filename;
+ }
bool exists = true; //generate unique name
int i = 0;
QString defaultName;
while (exists) {
++i;
- defaultName = Base + "_copy" + QString::number(i) + "." + Suffix;
- exists = QFile::exists (Path + QDir::separator() + defaultName);
+ defaultName = base + "_copy" + QString::number(i) + "." + suffix;
+ exists = QFile::exists(dir.filePath(defaultName));
}
bool ok;
QString s = QInputDialog::getText(tr("Copy file"), tr("Enter new name:"),
- QLineEdit::Normal, defaultName, &ok, this);
- if(!ok) return;
- if(s.isEmpty()) return;
-
- QString NewName;
- if(s.contains('.'))
- NewName = s;
- else
- NewName = s+"."+Suffix;
+ QLineEdit::Normal, defaultName, &ok, this);
+ if(ok && !s.isEmpty()) {
+ if (!s.endsWith(suffix)) {
+ s += QString(".") + suffix;
+ }
- if (QFile::exists(Path + QDir::separator() + NewName)) { //check New Name exists
- QMessageBox::critical(this, tr("error"), tr("Cannot copy file to identical name: ") + Name);
- return;
- }
+ if (QFile::exists(dir.filePath(s))) { //check New Name exists
+ QMessageBox::critical(this, tr("error"), tr("Cannot copy file to identical name: %1").arg(filename));
+ return;
+ }
- if (!QFile::copy(Path + QDir::separator() + Name,
- Path + QDir::separator() + NewName)) {
- QMessageBox::critical(this, tr("Error"), tr("Cannot copy schematic: ")+Name);
- return;
- }
- //TODO: maybe require disable edit here
+ if (!QFile::copy(dir.filePath(filename), dir.filePath(s))) {
+ QMessageBox::critical(this, tr("Error"), tr("Cannot copy schematic: %1").arg(filename));
+ return;
+ }
+ //TODO: maybe require disable edit here
- // refresh the schematic file path
- this->updateSchNameHash();
- this->updateSpiceNameHash();
+ // refresh the schematic file path
+ this->updateSchNameHash();
+ this->updateSpiceNameHash();
- if(!ProjName.isEmpty())
- readProjectFiles(); // re-read the content ListView
+ slotUpdateTreeview();
+ }
}
-// ----------------------------------------------------------
void QucsApp::slotCMenuRename()
{
- QTreeWidgetItem *Item = Content->currentItem();
- if(!Item) return;
+ QModelIndex idx = Content->currentIndex();
+
+ //test the item is valid
+ if (!idx.isValid() || !idx.parent().isValid()) { return; }
- QString Name = Item->text(0);
- if (findDoc (QucsSettings.QucsWorkDir.filePath(Name))) {
+ QString filename = idx.sibling(idx.row(), 0).data().toString();
+ QString file(QucsSettings.QucsWorkDir.filePath(filename));
+ QFileInfo fileinfo(file);
+
+ if (findDoc(file)) {
QMessageBox::critical(this, tr("Error"),
- tr("Cannot rename an open file!"));
+ tr("Cannot rename an open file!"));
return;
}
- QString Suffix = Name.section('.',-1); // remember suffix
- QString Base = Name.section('.',0,-2);
- if(Base.isEmpty()) Base = Name;
+ QString suffix = fileinfo.completeSuffix();
+ QString base = fileinfo.baseName();
+ if(base.isEmpty()) {
+ base = filename;
+ }
bool ok;
- QString s = QInputDialog::getText(tr("Rename file"), tr("Enter new name:"),
- QLineEdit::Normal, Base, &ok, this);
- if(!ok) return;
- if(s.isEmpty()) return;
-
- QString NewName;
- if(s.contains('.'))
- NewName = s;
- else
- NewName = s+"."+Suffix;
- QDir file(QucsSettings.QucsWorkDir.path());
- if(!file.rename(Name, NewName)) {
- QMessageBox::critical(this, tr("Error"), tr("Cannot rename file: ")+Name);
- return;
+ QString s = QInputDialog::getText(tr("Rename file"), tr("Enter new filename:"),
+ QLineEdit::Normal, base, &ok, this);
+ if(ok && !s.isEmpty()) {
+ if (!s.endsWith(suffix)) {
+ s += QString(".") + suffix;
+ }
+ QDir dir(QucsSettings.QucsWorkDir.path());
+ if(!dir.rename(filename, s)) {
+ QMessageBox::critical(this, tr("Error"), tr("Cannot rename file: %1").arg(filename));
+ return;
+ }
+
+ slotUpdateTreeview();
}
- Item->setText(0, NewName);
}
-// ----------------------------------------------------------
void QucsApp::slotCMenuDelete()
{
- QTreeWidgetItem *item = Content->currentItem();
- if(item == 0) return;
- QString FileName = QucsSettings.QucsWorkDir.filePath(item->text(0));
+ QModelIndex idx = Content->currentIndex();
- if (findDoc (FileName)) {
- QMessageBox::critical(this, tr("Error"),
- tr("Cannot delete an open file!"));
- return;
- }
+ //test the item is valid
+ if (!idx.isValid() || !idx.parent().isValid()) { return; }
- int No;
- No = QMessageBox::warning(this, tr("Warning"),
- tr("This will delete the file permanently! Continue ?"),
- tr("No"), tr("Yes"));
- if(No != 1) return;
+ QString filename = idx.sibling(idx.row(), 0).data().toString();
+ QString file(QucsSettings.QucsWorkDir.filePath(filename));
- if(!QFile::remove(FileName)) {
- QMessageBox::critical(this, tr("Error"),
- tr("Cannot delete schematic: ")+item->text(0));
+ if (findDoc (file)) {
+ QMessageBox::critical(this, tr("Error"), tr("Cannot delete an open file!"));
return;
}
- delete item;
-}
-
-// ----------------------------------------------------------
-QString QucsApp::fileType (const QString& Ext)
-{
- QString Type = tr("unknown");
- if (Ext == "v")
- Type = tr("Verilog source");
- else if (Ext == "va")
- Type = tr("Verilog-A source");
- else if (Ext == "vhd" || Ext == "vhdl")
- Type = tr("VHDL source");
- else if (Ext == "dat")
- Type = tr("data file");
- else if (Ext == "dpl")
- Type = tr("data display");
- else if (Ext == "sch")
- Type = tr("schematic");
- else if (Ext == "sym")
- Type = tr("symbol");
- else if (Ext == "vhdl.cfg" || Ext == "vhd.cfg")
- Type = tr("VHDL configuration");
- else if (Ext == "cfg")
- Type = tr("configuration");
- return Type;
-}
-
-// ----------------------------------------------------------
-// TODO -> not implemented yet
-// Deletes all files with that name (and suffix sch, dpl, dat, vhdl, etc.).
-void QucsApp::slotCMenuDelGroup ()
-{
- QTreeWidgetItem *item = Content->currentItem();
- if (item == 0)
- return;
- QString s = item->text (0);
- s = QucsDoc::fileBase (s); // cut off suffix from file name
-
- const char * extensions[] =
- { "sch", "dpl", "dat", "vhdl", "vhd", "v", "sym",
- "vhdl.cfg", "vhd.cfg", "va", 0 };
-
- int i;
- for (i = 0; extensions[i] != 0; i++) {
- QString Short = s + "." + extensions[i];
- QString Name = QucsSettings.QucsWorkDir.filePath (Short);
- // search, if files are open
- if (findDoc (Name)) {
- QMessageBox::critical(this, tr("Error"), tr("Cannot delete the open file \"%1\"!").arg(Short));
+ int No;
+ No = QMessageBox::warning(this, tr("Warning"),
+ tr("This will delete the file permanently! Continue ?"),
+ tr("No"), tr("Yes"));
+ if(No == 1) {
+ if(!QFile::remove(file)) {
+ QMessageBox::critical(this, tr("Error"),
+ tr("Cannot delete file: %1").arg(filename));
return;
}
}
-
-
- // check existence of files
- QString Str = "\n";
- for (i = 0; extensions[i] != 0; i++) {
- QString Short = s + "." + extensions[i];
- QString Long = QucsSettings.QucsWorkDir.filePath (Short);
- bool exists = QFile::exists (Long);
- if (exists)
- Str += Short + "\n";
- }
- int No;
- No = QMessageBox::warning (this, tr("Warning"),
- tr("This will delete the files%1permanently! Continue ?").arg(Str),
- tr("No"), tr("Yes"));
- if (No != 1)
- return;
-
- // file removal
- for (i = 0; extensions[i] != 0; i++) {
- QString Short = s + "." + extensions[i];
- QString Name = QucsSettings.QucsWorkDir.filePath (Short);
- bool exists = QFile::exists (Name);
- if (exists) {
- // remove files
- if (!QFile::remove (Name)) {
- QMessageBox::critical(this, tr("Error"), tr("Cannot delete %1: \"%2\"!").arg(fileType (extensions[i])).
- arg(Short));
- continue;
- }
- // remove items from listview
- //item = Content->findItem (Short, 0);
- if (item) {
- // TODO???
- //item->parent()->takeItem (item);
- delete item;
- }
- }
- }
+ slotUpdateTreeview();
}
-
-// ----------------------------------------------------------
-// Inserts the selected subschematic in the schematic
-void QucsApp::slotCMenuInsert ()
+void QucsApp::slotCMenuInsert()
{
- slotSelectSubcircuit(Content->currentItem());
+ slotSelectSubcircuit(Content->currentIndex());
}
// ################################################################
@@ -1256,87 +1119,6 @@ void QucsApp::slotButtonProjNew()
}
}
-// ----------------------------------------------------------
-// Reads all files in the project directory and sort them into the
-// content ListView
-void QucsApp::readProjectFiles()
-{
- // Delete the content files, but don't delete the parent items !!!
-/* TODO
- while(ConSchematics->firstChild())
- delete ConSchematics->firstChild();
- while(ConDisplays->firstChild())
- delete ConDisplays->firstChild();
- while(ConDatasets->firstChild())
- delete ConDatasets->firstChild();
- while(ConSources->firstChild())
- delete ConSources->firstChild();
- while(ConVerilog->firstChild())
- delete ConVerilog->firstChild();
- while(ConVerilogA->firstChild())
- delete ConVerilogA->firstChild();
- while(ConOthers->firstChild())
- delete ConOthers->firstChild();
- while(ConOctave->firstChild())
- delete ConOctave->firstChild();
-*/
-
- //Is this OK instead of the above??
- initContentListView();
-
- int n;
- // put all files into "Content"-ListView
- QStringList Elements = QucsSettings.QucsWorkDir.entryList("*", QDir::Files, QDir::Name);
- QStringList::iterator it;
- QString Str;
- ConSchematics->setExpanded(true);
- for(it = Elements.begin(); it != Elements.end(); ++it) {
- Str = QucsDoc::fileSuffix (*it);
- if(Str == "sch") {
- n = Schematic::testFile(QucsSettings.QucsWorkDir.filePath((*it).toAscii()));
- if(n >= 0) {
- if(n > 0) {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConSchematics);
- temp->setText(0, (*it).ascii());
- temp->setText(1, QString::number(n)+tr("-port"));
- }
- else {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConSchematics);
- temp->setText(0, (*it).ascii());
- }
- }
- }
- else if(Str == "dpl") {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConDisplays);
- temp->setText(0, (*it).ascii());
- }
- else if(Str == "dat") {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConDatasets);
- temp->setText(0, (*it).ascii());
- }
- else if((Str == "vhdl") || (Str == "vhd")) {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConSources);
- temp->setText(0, (*it).ascii());
- }
- else if(Str == "v") {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConVerilog);
- temp->setText(0, (*it).ascii());
- }
- else if(Str == "va") {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConVerilogA);
- temp->setText(0, (*it).ascii());
- }
- else if((Str == "m") || (Str == "oct")) {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConOctave);
- temp->setText(0, (*it).ascii());
- }
- else {
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConOthers);
- temp->setText(0, (*it).ascii());
- }
- }
-}
-
// ----------------------------------------------------------
// Opens an existing project.
void QucsApp::openProject(const QString& Path)
@@ -1366,11 +1148,7 @@ void QucsApp::openProject(const QString& Path)
QucsSettings.QucsWorkDir.setPath(ProjDir.path());
octave->adjustDirectory();
- QStringList headers;
- headers << tr("Content of ") + Name << tr("Note");
- Content->setHeaderLabels(headers);
-
- readProjectFiles();
+ Content->setProjPath(QucsSettings.QucsWorkDir.absolutePath());
TabView->setCurrentPage(1); // switch to "Content"-Tab
ProjName = Name; // remember the name of project
@@ -1430,11 +1208,7 @@ void QucsApp::slotMenuProjClose()
QucsSettings.QucsWorkDir.setPath(QDir::homeDirPath()+QDir::convertSeparators ("/.qucs"));
octave->adjustDirectory();
- QStringList headers;
- headers << tr("Content of") << tr("Note");
- Content->setHeaderLabels(headers);
-
- initContentListView();
+ Content->setProjPath("");
TabView->setCurrentPage(0); // switch to "Projects"-Tab
ProjName = "";
@@ -1638,6 +1412,7 @@ bool QucsApp::saveFile(QucsDoc *Doc)
if(Result < 0) return false;
updatePortNumber(Doc, Result);
+ slotUpdateTreeview();
return true;
}
@@ -1659,7 +1434,7 @@ void QucsApp::slotFileSave()
statusBar()->message(tr("Ready."));
if(!ProjName.isEmpty())
- readProjectFiles(); // re-read the content ListView
+ slotUpdateTreeview();
}
// --------------------------------------------------------------
@@ -1741,36 +1516,11 @@ bool QucsApp::saveAs()
lastDirOpenSave = Info.dirPath(true); // remember last directory and file
updateRecentFilesList(s);
- if(intoView) { // insert new name in Content ListView ?
- if(Info.dirPath(true) == QucsSettings.QucsWorkDir.absPath())
- if(!ProjName.isEmpty()) {
- s = Info.fileName(); // remove path from file name
- QString ext = Info.extension (false);
- /*
- if(ext == "sch")
- Content->setSelected(new Q3ListViewItem(ConSchematics, s), true);
- else if(ext == "dpl")
- Content->setSelected(new Q3ListViewItem(ConDisplays, s), true);
- else if(ext == "dat")
- Content->setSelected(new Q3ListViewItem(ConDatasets, s), true);
- else if((ext == "vhdl") || (ext == "vhd"))
- Content->setSelected(new Q3ListViewItem(ConSources, s), true);
- else if(ext == "v")
- Content->setSelected(new Q3ListViewItem(ConVerilog, s), true);
- else if(ext == "va")
- Content->setSelected(new Q3ListViewItem(ConVerilogA, s), true);
- else if(ext == "m" || ext == "oct")
- Content->setSelected(new Q3ListViewItem(ConOctave, s), true);
- else
- Content->setSelected(new Q3ListViewItem(ConOthers, s), true);
-*/
- }
- }
-
n = Doc->save(); // SAVE
if(n < 0) return false;
updatePortNumber(Doc, n);
+ slotUpdateTreeview();
return true;
}
@@ -1796,7 +1546,7 @@ void QucsApp::slotFileSaveAs()
this->updateSpiceNameHash();
if(!ProjName.isEmpty())
- readProjectFiles(); // re-read the content ListView
+ slotUpdateTreeview();
}
@@ -1828,6 +1578,8 @@ void QucsApp::slotFileSaveAll()
// refresh the schematic file path
this->updateSchNameHash();
this->updateSpiceNameHash();
+
+ slotUpdateTreeview();
}
// --------------------------------------------------------------
@@ -2053,19 +1805,6 @@ void QucsApp::updatePortNumber(QucsDoc *currDoc, int No)
if (ext == "sch") {
Model = "Sub";
-
- // enter new port number into ListView
- // TODO I'm not sure if I do things correctly here -> RECHECK!!!
- QTreeWidgetItem *p;
- //for(p = ConSchematics->firstChild(); p!=0; p = p->nextSibling()) {
- for(int i=0; ichildCount(); i++) {
- p = ConSchematics->child(i);
- if(p->text(0) == Name) {
- if(No == 0) p->setText(1,"");
- else p->setText(1,QString::number(No)+tr("-port"));
- break;
- }
- }
}
else if (ext == "vhdl" || ext == "vhd") {
Model = "VHDL";
@@ -2344,10 +2083,6 @@ void QucsApp::slotAfterSimulation(int Status, SimMessage *sim)
if(!isTextDocument (sim->DocWidget))
((Schematic*)sim->DocWidget)->viewport()->update();
- // put all dataset files into "Content"-ListView (update)
-/* QStringList Elements = ProjDir.entryList("*.dat", QDir::Files, QDir::Name);
- for(it = Elements.begin(); it != Elements.end(); ++it)
- new QListViewItem(ConDatasets, (*it).ascii());*/
}
// ------------------------------------------------------------------------
@@ -2392,10 +2127,8 @@ void QucsApp::slotChangePage(QString& DocName, QString& DataDisplay)
}
else {
if(file.open(QIODevice::ReadWrite)) { // if document doesn't exist, create
- //TODO RECHECK!! new Q3ListViewItem(ConDisplays, DataDisplay); // add new name
- QTreeWidgetItem *temp = new QTreeWidgetItem(ConDisplays);
- temp->setText(0,DataDisplay);
d->DataDisplay = Info.fileName();
+ slotUpdateTreeview();
}
else {
QMessageBox::critical(this, tr("Error"), tr("Cannot create ")+Name);
@@ -2438,35 +2171,29 @@ void QucsApp::slotToPage()
}
// -------------------------------------------------------------------
-// Is called when a double-click is made in the content ListView.
-void QucsApp::slotOpenContent(QTreeWidgetItem *item)
+// Changes to the data display of current page.
+void QucsApp::slotOpenContent(const QModelIndex &idx)
{
editText->setHidden(true); // disable text edit of component property
- if(item == 0) return; // no item was double clicked
- if(item->parent() == 0) return; // no document, but item "schematic", ...
-
-/*
- QucsSettings.QucsWorkDir.setPath(QucsSettings.QucsHomeDir.path());
- QString p = ProjName+"_prj";
- if(!QucsSettings.QucsWorkDir.cd(p)) {
- QMessageBox::critical(this, tr("Error"),
- tr("Cannot access project directory: ")+
- QucsSettings.QucsWorkDir.path()+QDir::separator()+p);
- return;
- }*/
+ //test the item is valid
+ if (!idx.isValid()) { return; }
+ if (!idx.parent().isValid()) { return; }
- QFileInfo Info(QucsSettings.QucsWorkDir.filePath(item->text(0)));
- QString Suffix = Info.extension(false);
+ QString filename = idx.sibling(idx.row(), 0).data().toString();
+ QString note = idx.sibling(idx.row(), 1).data().toString();
+ QFileInfo Info(QucsSettings.QucsWorkDir.filePath(filename));
+ QString extName = Info.completeSuffix();
- if (Suffix == "sch" || Suffix == "dpl" || Suffix == "vhdl" ||
- Suffix == "vhd" || Suffix == "v" || Suffix == "va" ||
- Suffix == "m" || Suffix == "oct") {
+ if (extName == "sch" || extName == "dpl" || extName == "vhdl" ||
+ extName == "vhd" || extName == "v" || extName == "va" ||
+ extName == "m" || extName == "oct") {
gotoPage(Info.absFilePath());
updateRecentFilesList(Info.absFilePath());
+ slotUpdateRecentFiles();
- if(item->text(1).isEmpty()) // is subcircuit ?
- if(Suffix == "sch") return;
+ if(note.isEmpty()) // is subcircuit ?
+ if(extName == "sch") return;
select->blockSignals(true); // switch on the 'select' action ...
select->setChecked(true);
@@ -2480,20 +2207,20 @@ void QucsApp::slotOpenContent(QTreeWidgetItem *item)
return;
}
- if(Suffix == "dat") {
+ if(extName == "dat") {
editFile(Info.absFilePath()); // open datasets with text editor
return;
}
-
// File is no Qucs file, so go through list and search a user
// defined program to open it.
QStringList com;
- QStringList::Iterator it = QucsSettings.FileTypes.begin();
- while(it != QucsSettings.FileTypes.end()) {
- if(Suffix == (*it).section('/',0,0)) {
+ QStringList::const_iterator it = QucsSettings.FileTypes.constBegin();
+ while(it != QucsSettings.FileTypes.constEnd()) {
+ if(extName == (*it).section('/',0,0)) {
com = QStringList::split(" ", (*it).section('/',1,1));
com << Info.absFilePath();
+
QProcess *Program = new QProcess();
//Program->setCommunication(0);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
@@ -2517,30 +2244,36 @@ void QucsApp::slotOpenContent(QTreeWidgetItem *item)
// ---------------------------------------------------------
// Is called when the mouse is clicked within the Content QListView.
-void QucsApp::slotSelectSubcircuit(QTreeWidgetItem *item)
+void QucsApp::slotSelectSubcircuit(const QModelIndex &idx)
{
editText->setHidden(true); // disable text edit of component property
- if(item == 0) { // mouse button pressed not over an item ?
+ if(!idx.isValid()) { // mouse button pressed not over an item ?
Content->clearSelection(); // deselect component in ListView
return;
}
-
bool isVHDL = false;
bool isVerilog = false;
- if(item->parent() == 0) return;
- if(item->parent()->text(0) == tr("Schematics")) {
- if(item->text(1).isEmpty())
+ QModelIndex parentIdx = idx.parent();
+ if(!parentIdx.isValid()) { return; }
+
+ QString category = parentIdx.data().toString();
+
+ if(category == tr("Schematics")) {
+ if(idx.sibling(idx.row(), 1).data().toString().isEmpty())
return; // return, if not a subcircuit
}
- else if(item->parent()->text(0) == tr("VHDL"))
+ else if(category == tr("VHDL"))
isVHDL = true;
- else if(item->parent()->text(0) == tr("Verilog"))
+ else if(category == tr("Verilog"))
isVerilog = true;
else
return;
+ QString filename = idx.sibling(idx.row(), 0).data().toString();
+ QString note = idx.sibling(idx.row(), 1).data().toString();
+
// delete previously selected elements
if(view->selElem != 0) delete view->selElem;
view->selElem = 0;
@@ -2560,7 +2293,7 @@ void QucsApp::slotSelectSubcircuit(QTreeWidgetItem *item)
Comp = new Verilog_File();
else
Comp = new Subcircuit();
- Comp->Props.first()->Value = item->text(0);
+ Comp->Props.first()->Value = idx.sibling(idx.row(), 0).data().toString();
Comp->recreate(0);
view->selElem = Comp;
@@ -2573,7 +2306,6 @@ void QucsApp::slotSelectSubcircuit(QTreeWidgetItem *item)
MouseDoubleClickAction = 0;
}
-
// ---------------------------------------------------------
// Is called when the mouse is clicked within the Content QListView.
void QucsApp::slotSelectLibComponent(QTreeWidgetItem *item)
@@ -2584,18 +2316,9 @@ void QucsApp::slotSelectLibComponent(QTreeWidgetItem *item)
// if the current document is a schematic activate the paste
if(!Doc->inherits("QPlainTextEdit"))
{
-
- if(item == 0)
- {
- // mouse button pressed not over an item ?
- Content->clearSelection(); // deselect component in ListView
- return;
- }
-
// if theres not a higher level item, this is a top level item,
// not a component item so return
if(item->parent() == 0) return;
-
if(item->text(1).isEmpty()) return; // return, if not a subcircuit
// copy the subcircuit schematic to the clipboard
@@ -2897,6 +2620,14 @@ void QucsApp::slotHideEdit()
editText->setHidden(true);
}
+// -----------------------------------------------------------
+// Update project view by call refresh function
+// looses the focus.
+void QucsApp::slotUpdateTreeview()
+{
+ Content->refresh();
+}
+
// -----------------------------------------------------------
// Searches the qucs path list for all schematic files and creates
// a hash for lookup later
diff --git a/qucs/qucs/qucs.h b/qucs/qucs/qucs.h
index 611e65b371..3860036865 100644
--- a/qucs/qucs/qucs.h
+++ b/qucs/qucs/qucs.h
@@ -30,6 +30,7 @@ class MouseActions;
class SearchDialog;
class OctaveWindow;
class MessageDock;
+class ProjectView;
class QLabel;
class QAction;
@@ -126,21 +127,22 @@ public slots:
// for menu that appears by right click in content ListView
void slotShowContentMenu(const QPoint &);
+
void slotCMenuOpen();
void slotCMenuCopy();
void slotCMenuRename();
void slotCMenuDelete();
- void slotCMenuDelGroup();
void slotCMenuInsert();
+ void slotUpdateTreeview();
private slots:
void slotMenuProjOpen();
void slotMenuProjClose();
void slotMenuProjDel();
void slotListProjOpen(const QModelIndex &);
- void slotSelectSubcircuit(QTreeWidgetItem*);
+ void slotSelectSubcircuit(const QModelIndex &);
void slotSelectLibComponent(QTreeWidgetItem*);
- void slotOpenContent(QTreeWidgetItem*);
+ void slotOpenContent(const QModelIndex &);
void slotSetCompView(int);
void slotButtonProjNew();
void slotButtonProjOpen();
@@ -165,7 +167,7 @@ private slots:
QMenu *ContentMenu;
// corresponding actions
- QAction *ActionCMenuOpen, *ActionCMenuCopy, *ActionCMenuRename, *ActionCMenuDelete, *ActionCMenuDelGroup, *ActionCMenuInsert;
+ QAction *ActionCMenuOpen, *ActionCMenuCopy, *ActionCMenuRename, *ActionCMenuDelete, *ActionCMenuInsert;
QAction *fileNew, *textNew, *fileNewDpl, *fileOpen, *fileSave, *fileSaveAs,
*fileSaveAll, *fileClose, *fileExamples, *fileSettings, *filePrint, *fileQuit,
@@ -186,9 +188,7 @@ private slots:
MessageDock *messageDock;
QListView *Projects;
- QTreeWidget *Content;
- QTreeWidgetItem *ConSchematics, *ConSources, *ConDisplays, *ConDatasets,
- *ConOthers, *ConVerilog, *ConVerilogA, *ConOctave;
+ ProjectView *Content;
QLineEdit *CompSearch;
QPushButton *CompSearchClear;
@@ -203,7 +203,6 @@ private slots:
// ********** Methods ***************************************************
void initView();
void initCursorMenu();
- void initContentListView();
void printCurrentDocument(bool);
bool saveFile(QucsDoc *Doc=0);
@@ -226,7 +225,6 @@ private slots:
public:
void readProjects();
- void readProjectFiles();
void updatePathList(void); // update the list of paths, pruning non-existing paths
void updatePathList(QStringList);
void updateSchNameHash(void); // maps all schematic files in the path list
diff --git a/qucs/qucs/qucs_actions.cpp b/qucs/qucs/qucs_actions.cpp
index 870b388e06..0c7e0b0072 100644
--- a/qucs/qucs/qucs_actions.cpp
+++ b/qucs/qucs/qucs_actions.cpp
@@ -36,7 +36,9 @@
#include
#include
#include
+#include
+#include "projectView.h"
#include "main.h"
#include "qucs.h"
#include "schematic.h"
@@ -950,7 +952,7 @@ void QucsApp::slotAddToProject()
}
free(Buffer);
- readProjectFiles(); // re-read the content ListView
+ slotUpdateTreeview();
statusBar()->message(tr("Ready."));
}
@@ -1238,7 +1240,8 @@ void QucsApp::slotCreateLib()
return;
}
- LibraryDialog *d = new LibraryDialog(this, ConSchematics);
+ LibraryDialog *d = new LibraryDialog(this);
+ d->fillSchematicList(Content->exportSchematic());
d->exec();
}
@@ -1254,7 +1257,7 @@ void QucsApp::slotImportData()
ImportDialog *d = new ImportDialog(this);
if(d->exec() == QDialog::Accepted)
- readProjectFiles(); // re-read all project files
+ slotUpdateTreeview();
}
// -----------------------------------------------------------