git-svn-id: svn://db.shs.com.ru/libs@240 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
BlockEditor::BlockEditor(QWidget *parent) : QWidget(parent), ui(new Ui::BlockEditor) {
|
||||
init = false;
|
||||
ui->setupUi(this);
|
||||
src_title = windowTitle();
|
||||
connect(ui->blockView->scene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
|
||||
block.setFlags(0);
|
||||
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) {
|
||||
BlockItem b;
|
||||
b.loadModel(model);
|
||||
@@ -153,6 +165,7 @@ void BlockEditor::on_buttonSave_clicked() {
|
||||
if (f.open(QIODevice::WriteOnly)) {
|
||||
cur_file = c;
|
||||
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() {
|
||||
QString c = QFileDialog::getOpenFileName(this, "Save block model to file", cur_file, "*.blockmodel");
|
||||
if (!c.isEmpty()) {
|
||||
QFile f(c);
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
cur_file = c;
|
||||
loadModel(f.readAll());
|
||||
}
|
||||
}
|
||||
loadFile(c);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
|
||||
|
||||
public slots:
|
||||
void loadFile(QString path);
|
||||
void loadModel(const QByteArray & model);
|
||||
QByteArray saveModel();
|
||||
|
||||
@@ -48,7 +49,7 @@ private:
|
||||
Ui::BlockEditor *ui;
|
||||
QMap<int, QTreeWidgetItem*> pin_tli;
|
||||
BlockItem block;
|
||||
QString cur_file;
|
||||
QString src_title, cur_file;
|
||||
bool init;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>901</width>
|
||||
<height>861</height>
|
||||
<width>847</width>
|
||||
<height>810</height>
|
||||
</rect>
|
||||
</property>
|
||||
<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>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
@@ -31,6 +35,12 @@
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<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">
|
||||
<number>4</number>
|
||||
</property>
|
||||
@@ -166,7 +176,7 @@
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/list-add.png</normaloff>:/icons/list-add.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -177,7 +187,7 @@
|
||||
<string>Clone</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/edit-copy.png</normaloff>:/icons/edit-copy.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -204,7 +214,7 @@
|
||||
<string>Remove selected</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -215,7 +225,7 @@
|
||||
<string>Remove all</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -289,19 +299,16 @@
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonSave">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
<string>Save ...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -309,9 +316,12 @@
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -319,19 +329,16 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonLoad">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load</string>
|
||||
<string>Load ...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/document-open.png</normaloff>:/icons/document-open.png</iconset>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -353,7 +360,7 @@
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -363,12 +370,15 @@
|
||||
</layout>
|
||||
<action name="actionRemove_items">
|
||||
<property name="icon">
|
||||
<iconset resource="qad_blockview.qrc">
|
||||
<iconset resource="../qad_blockview.qrc">
|
||||
<normaloff>:/icons/edit-delete.png</normaloff>:/icons/edit-delete.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove items</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Del</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
@@ -384,7 +394,7 @@
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="qad_blockview.qrc"/>
|
||||
<include location="../qad_blockview.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
int main(int argc, char * argv[]) {
|
||||
QApplication a(argc, argv);
|
||||
BlockEditor w;
|
||||
if (a.arguments().size() > 1)
|
||||
w.loadFile(a.arguments().back());
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user