Esempio n. 1
0
    def __init__(self,
                 history_projects: [ProjectDocument, None] = None,
                 parent=None):
        super(HistoryProjectManager, self).__init__(parent)

        self._history_projects = history_projects if history_projects else []
        self._workbench_view = GraphicsView()
        self._workbench_view.setObjectName("history_view")
        self._workbench_view.setBackgroundBrush(QColor(147, 147, 147))
        self._current_project = ProjectDocument()
Esempio n. 2
0
    def open_new_project(self):
        file_format = "Project files (*.mfb)"
        dir_ = "."
        file_names = QFileDialog.getOpenFileNames(self, "选择遥感图片", dir_,
                                                  file_format)[0]

        if file_names:
            project_format = ProjectFormat()
            had_files = self._history_project_manger.get_all_files()

            for file in file_names:
                if file == self._origin_project.get_file_name(
                ) or file in had_files:
                    continue
                project = ProjectDocument(project_format.read_project(file))
                if not project:
                    continue
                self._history_project_manger.add_history_project(project)
                self.add_project(project)
        else:
            return None
Esempio n. 3
0
    def open_history_project(self):
        dir_ = os.path.dirname(self.window_state_data.recent_files[0]) \
            if self.window_state_data.recent_files else os.path.dirname(".")

        file_format = "Project files (*.mfb)"
        file_names = QFileDialog.getOpenFileNames(self, "选择遥感图片", dir_, file_format)[0]

        if file_names:
            project_format = ProjectFormat()
            project_documents = []
            for file in file_names:
                if not os.path.exists(file):
                    continue
                if file == self.center_tab_widget.currentWidget().get_file_name():
                    continue
                project = ProjectDocument(project_format.read_project(file))
                if not project:
                    continue
                project_documents.append(project)
            return project_documents
        else:
            return None
Esempio n. 4
0
    def set_scene(self, project: ProjectDocument):
        if self._current_project == project:
            return

        self._current_project = project
        self._workbench_view.setScene(project.get_scene())
Esempio n. 5
0
class HistoryProjectManager(QObject):
    def __init__(self,
                 history_projects: [ProjectDocument, None] = None,
                 parent=None):
        super(HistoryProjectManager, self).__init__(parent)

        self._history_projects = history_projects if history_projects else []
        self._workbench_view = GraphicsView()
        self._workbench_view.setObjectName("history_view")
        self._workbench_view.setBackgroundBrush(QColor(147, 147, 147))
        self._current_project = ProjectDocument()

    def set_scene(self, project: ProjectDocument):
        if self._current_project == project:
            return

        self._current_project = project
        self._workbench_view.setScene(project.get_scene())

    def get_view(self) -> QGraphicsView:
        return self._workbench_view

    def synchronize_with_origin_view(self, other_view: GraphicsView):
        self._workbench_view.setTransform(other_view.transform())

        self._workbench_view.verticalScrollBar().setValue(
            GraphicsView.adjust_scrollbar_value(
                self._workbench_view.verticalScrollBar().maximum(),
                other_view.verticalScrollBar().maximum(),
                other_view.verticalScrollBar().value()))
        self._workbench_view.horizontalScrollBar().setValue(
            GraphicsView.adjust_scrollbar_value(
                self._workbench_view.horizontalScrollBar().maximum(),
                other_view.horizontalScrollBar().maximum(),
                other_view.horizontalScrollBar().value()))

    def hidden_view(self, hidden: bool):
        self._workbench_view.setHidden(hidden)

    def get_projects_document(self) -> list:
        return self._history_projects

    def get_projects(self) -> list:
        projects = []
        for project_doc in self._history_projects:
            projects.append(project_doc.project())
        return projects

    def get_all_files(self) -> tuple:
        files = []
        for project in self._history_projects:
            files.append(project.project_full_path())
        return tuple(files)

    def set_history_projects(self, history_projects: list):
        if not isinstance(history_projects, (tuple, list)):
            self._history_projects.append(history_projects)
            return
        if len(set(self._history_projects).difference(history_projects)) <= 0:
            return
        self._history_projects = history_projects

    def add_history_project(self, history_project: ProjectDocument):
        if not isinstance(history_project, ProjectDocument):
            return
        if history_project not in self._history_projects:
            self._history_projects.append(history_project)

    def remove_history_project(self, history_project: ProjectDocument):
        if not isinstance(history_project, ProjectDocument):
            return
        if history_project in self._history_projects:
            self._history_projects.remove(history_project)
            del history_project

    def get_project_pixmaps(self):
        pixmaps = []
        for project in self._history_projects:
            pixmaps.append(project.get_pixmap())
        return pixmaps

    def current_index_changed(self, index):
        if 0 <= index < len(self._history_projects):
            self._history_projects[index].set_scale(
                self._workbench_view.transform().m11())
            self.set_scene(self._history_projects[index])

    def browser_result(self):
        self._workbench_view.setBackgroundBrush(QColor(Qt.black))
        self._current_project.get_pixmap_item().setVisible(False)
        [
            item.is_browser_result(True)
            for item in self._current_project.get_scene().items()
            if isinstance(item, OutlineItem)
        ]

        # for item in items:
        #     item.is_browser_result(True)

    def end_browser(self):
        self._workbench_view.setBackgroundBrush(QColor(147, 147, 147))
        self._current_project.get_pixmap_item().setVisible(True)

        [
            item.is_browser_result(False)
            for item in self._current_project.get_scene().items()
            if isinstance(item, OutlineItem)
        ]
Esempio n. 6
0
    def __init__(self,
                 gadget,
                 toolbar_gadget,
                 file_name=None,
                 project_name=None,
                 image_path=None,
                 person_name=None,
                 parent=None,
                 eraser_size=3,
                 eraser_option=SelectionOptionToolBar.Subtract):
        super(Document, self).__init__(parent)
        ProjectDocument.__init__(self, parent=parent)

        self._writer_format = ProjectFormat()
        self._reader_format = ProjectFormat()
        self._export_format = ProjectFormat()

        self._mark_item_to_outline_item = {}
        self._modifier = False

        self._project = Project(image_path, file_name, project_name,
                                person_name)
        self._image_path = image_path if image_path else self._project.image_path

        self._current_tool = gadget
        self._selection_option = toolbar_gadget
        self._eraser_size = eraser_size
        self._eraser_option = eraser_option

        self.__current_index = -1
        self.__mouse_press_index = -1
        self.__mouse_press_offset = QPoint()
        self.__resize_handel_pressed = False
        self.__undo_stack = QUndoStack(self)
        self._selection_item = None
        self._history_widget = None
        self._history_project_manager = None
        self._mark_item_manager = MarkItemManager()
        self._mark_item_manager.selected_item_changed.connect(
            self.selected_mark_item_changed)

        # # 创建场景
        self._workbench_scene.setObjectName("workbench_scene")

        self._is_big_img = False
        # if self._is_big_img:
        #     self.workbench_view = LoadIMGraphicsView(self._mark_item_manager, gadget, toolbar_gadget, eraser_size,
        #                                              image_path, self._workbench_scene, parent=self)
        # else:
        self.workbench_view = GraphicsViewTest(self._mark_item_manager,
                                               gadget,
                                               toolbar_gadget,
                                               eraser_size,
                                               parent=self)
        # 把场景添加到视图中
        self.workbench_view.setScene(self._workbench_scene)

        self.workbench_view.setObjectName("workbench_view")
        self.workbench_view.setContentsMargins(0, 0, 0, 0)
        self.workbench_view.setBackgroundBrush(QColor(147, 147, 147))

        # 布局
        self.tab_vertical_layout = QVBoxLayout(self)
        self._splitter1 = QSplitter(self)
        self._splitter1.setStyleSheet("margin: 0px")
        self._splitter1.addWidget(self.workbench_view)

        self._splitter2 = QSplitter(self)
        self._splitter2.setOrientation(Qt.Vertical)
        self._splitter2.setStyleSheet("margin: 0px")
        self._splitter2.addWidget(self._splitter1)

        self.tab_vertical_layout.addWidget(self._splitter2)
        self.tab_vertical_layout.setContentsMargins(0, 0, 0, 0)

        # 当前选择小工具
        self.change_gadget(gadget)

        # 信号接收
        self.workbench_view.border_moved_signal.connect(self.border_moved)
        self.workbench_view.border_created.connect(self.created_border)
        self.workbench_view.about_to_create_border.connect(
            self.about_to_create_border)
        self.workbench_view.eraser_action_signal.connect(self.eraser_action)

        if all([image_path, project_name, file_name]) and not self._is_big_img:
            self.create_document()