git-svn-id: svn://db.shs.com.ru/libs@240 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2017-06-17 14:17:45 +00:00
parent f437066f27
commit 9e201747ea
4 changed files with 55 additions and 35 deletions

View File

@@ -12,6 +12,7 @@
BlockEditor::BlockEditor(QWidget *parent) : QWidget(parent), ui(new Ui::BlockEditor) { BlockEditor::BlockEditor(QWidget *parent) : QWidget(parent), ui(new Ui::BlockEditor) {
init = false; init = false;
ui->setupUi(this); ui->setupUi(this);
src_title = windowTitle();
connect(ui->blockView->scene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(ui->blockView->scene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
block.setFlags(0); block.setFlags(0);
ui->blockView->addItem(&block); ui->blockView->addItem(&block);
@@ -50,6 +51,17 @@ BlockEditor::~BlockEditor() {
} }
void BlockEditor::loadFile(QString path) {
if (path.isEmpty()) return;
QFile f(path);
if (f.open(QIODevice::ReadOnly)) {
cur_file = path;
loadModel(f.readAll());
}
setWindowTitle(src_title + QString(" - %1").arg(QFileInfo(path).baseName()));
}
void BlockEditor::loadModel(const QByteArray &model) { void BlockEditor::loadModel(const QByteArray &model) {
BlockItem b; BlockItem b;
b.loadModel(model); b.loadModel(model);
@@ -153,6 +165,7 @@ void BlockEditor::on_buttonSave_clicked() {
if (f.open(QIODevice::WriteOnly)) { if (f.open(QIODevice::WriteOnly)) {
cur_file = c; cur_file = c;
f.write(saveModel()); f.write(saveModel());
setWindowTitle(src_title + QString(" - %1").arg(QFileInfo(c).baseName()));
} }
} }
} }
@@ -160,13 +173,7 @@ void BlockEditor::on_buttonSave_clicked() {
void BlockEditor::on_buttonLoad_clicked() { void BlockEditor::on_buttonLoad_clicked() {
QString c = QFileDialog::getOpenFileName(this, "Save block model to file", cur_file, "*.blockmodel"); QString c = QFileDialog::getOpenFileName(this, "Save block model to file", cur_file, "*.blockmodel");
if (!c.isEmpty()) { loadFile(c);
QFile f(c);
if (f.open(QIODevice::ReadOnly)) {
cur_file = c;
loadModel(f.readAll());
}
}
} }

View File

@@ -22,6 +22,7 @@ public:
public slots: public slots:
void loadFile(QString path);
void loadModel(const QByteArray & model); void loadModel(const QByteArray & model);
QByteArray saveModel(); QByteArray saveModel();
@@ -48,7 +49,7 @@ private:
Ui::BlockEditor *ui; Ui::BlockEditor *ui;
QMap<int, QTreeWidgetItem*> pin_tli; QMap<int, QTreeWidgetItem*> pin_tli;
BlockItem block; BlockItem block;
QString cur_file; QString src_title, cur_file;
bool init; bool init;
}; };

View File

@@ -6,12 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>901</width> <width>847</width>
<height>861</height> <height>810</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Block editor</string>
</property>
<property name="windowIcon">
<iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/blockview.png</normaloff>:/icons/blockview.png</iconset>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
@@ -31,6 +35,12 @@
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="margin"> <property name="margin">
<number>4</number> <number>4</number>
</property> </property>
@@ -166,7 +176,7 @@
<string>Add</string> <string>Add</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset> <normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
</property> </property>
</widget> </widget>
@@ -177,7 +187,7 @@
<string>Clone</string> <string>Clone</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/edit-copy.png</normaloff>:/icons/edit-copy.png</iconset> <normaloff>:/icons/edit-copy.png</normaloff>:/icons/edit-copy.png</iconset>
</property> </property>
</widget> </widget>
@@ -204,7 +214,7 @@
<string>Remove selected</string> <string>Remove selected</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset> <normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property> </property>
</widget> </widget>
@@ -215,7 +225,7 @@
<string>Remove all</string> <string>Remove all</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset> <normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property> </property>
</widget> </widget>
@@ -289,19 +299,16 @@
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<item> <item>
<widget class="QPushButton" name="buttonSave"> <widget class="QPushButton" name="buttonSave">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Save</string> <string>Save ...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset> <normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
</property> </property>
<property name="shortcut">
<string>Ctrl+S</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@@ -309,9 +316,12 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>20</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@@ -319,19 +329,16 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="buttonLoad"> <widget class="QPushButton" name="buttonLoad">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Load</string> <string>Load ...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset> <normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
</property> </property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
</widget> </widget>
</item> </item>
<item> <item>
@@ -353,7 +360,7 @@
<string>Clear</string> <string>Clear</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset> <normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
</property> </property>
</widget> </widget>
@@ -363,12 +370,15 @@
</layout> </layout>
<action name="actionRemove_items"> <action name="actionRemove_items">
<property name="icon"> <property name="icon">
<iconset resource="qad_blockview.qrc"> <iconset resource="../qad_blockview.qrc">
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset> <normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
</property> </property>
<property name="text"> <property name="text">
<string>Remove items</string> <string>Remove items</string>
</property> </property>
<property name="shortcut">
<string>Del</string>
</property>
</action> </action>
</widget> </widget>
<customwidgets> <customwidgets>
@@ -384,7 +394,7 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="qad_blockview.qrc"/> <include location="../qad_blockview.qrc"/>
</resources> </resources>
<connections> <connections>
<connection> <connection>

View File

@@ -5,6 +5,8 @@
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
BlockEditor w; BlockEditor w;
if (a.arguments().size() > 1)
w.loadFile(a.arguments().back());
w.show(); w.show();
return a.exec(); return a.exec();
} }